Skip to content

Commit

Permalink
django: admin dashboard: make some fields read-only
Browse files Browse the repository at this point in the history
Signed-off-by: Jonas Remmert <jremmert@gmx.net>
  • Loading branch information
jonas-rem committed Jun 4, 2024
1 parent fc2c349 commit 7457f5a
Showing 1 changed file with 20 additions and 5 deletions.
25 changes: 20 additions & 5 deletions server/django/sensordata/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,29 @@
class DeviceAdmin(admin.ModelAdmin):
list_display = ('device_id', 'name')
search_fields = ('device_id', 'name')

readonly_fields = ('device_id', 'name')

def get_model_perms(self, request):
return {
'add': False,
'change': False,
'delete': False,
'view': True,
}

@admin.register(ResourceType)
class ResourceTypeAdmin(admin.ModelAdmin):
list_display = ('object_id', 'resource_id', 'name', 'data_type')
search_fields = ('object_id', 'resource_id', 'name')
readonly_fields = ('object_id', 'resource_id', 'name', 'data_type')

def get_model_perms(self, request):
return {
'add': False,
'change': False,
'delete': False,
'view': True,
}


@admin.register(Resource)
Expand All @@ -49,15 +66,15 @@ class EventAdmin(admin.ModelAdmin):
class EventResourceAdmin(admin.ModelAdmin):
list_display = ('event', 'resource')
search_fields = ('event__event_type', 'resource__resource_type__name')
list_filter = ('event', 'resource')
list_filter = ('event', 'resource__resource_type')


@admin.register(DeviceOperation)
class DeviceOperationAdmin(admin.ModelAdmin):
list_display = ('resource', 'operation_type', 'status', 'timestamp_sent',
'retransmit_counter', 'last_attempt')
search_fields = ('resource__device__device_id', 'operation_type', 'status')
list_filter = ('resource', 'operation_type', 'status', 'timestamp_sent')
list_filter = ('resource__resource_type', 'operation_type', 'status', 'timestamp_sent')
readonly_fields = ('status', 'timestamp_sent', 'retransmit_counter',
'last_attempt', 'operation_type')

Expand Down Expand Up @@ -120,5 +137,3 @@ def save_model(self, request, obj, form, change):
@admin.register(Firmware)
class FirmwareAdmin(admin.ModelAdmin):
list_display = ('version', 'file_name', 'download_url', 'created_at')
search_fields = ('version', 'file_name')
list_filter = ('created_at',)

0 comments on commit 7457f5a

Please sign in to comment.