Skip to content

Commit

Permalink
Merge pull request #393 from maykinmedia/feature/315-extra-admin-fields
Browse files Browse the repository at this point in the history
✨ [#315] added extra version and uuid fields in admin
  • Loading branch information
bart-maykin authored Jun 4, 2024
2 parents 4549268 + 491d1ab commit b4ebbeb
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 4 deletions.
22 changes: 20 additions & 2 deletions src/objects/core/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@

@admin.register(ObjectType)
class ObjectTypeAdmin(admin.ModelAdmin):
list_display = (
"_name",
"uuid",
)
readonly_fields = ("_name",)


Expand Down Expand Up @@ -52,15 +56,29 @@ def get_corrected_by(self, obj):

@admin.register(Object)
class ObjectAdmin(admin.ModelAdmin):
list_display = ("id", "object_type", "current_record")
list_display = (
"id",
"object_type",
"current_record",
"uuid",
"get_object_type_uuid",
)
search_fields = ("uuid", "records__data")
inlines = (ObjectRecordInline,)
list_filter = ("object_type",)

@admin.display(description="Object type UUID")
def get_object_type_uuid(self, obj):
return obj.object_type.uuid

def get_readonly_fields(self, request, obj=None):
readonly_fields = super().get_readonly_fields(request, obj)

if obj:
readonly_fields = ("uuid", "object_type") + readonly_fields
readonly_fields = (
"uuid",
"get_object_type_uuid",
"object_type",
) + readonly_fields

return readonly_fields
25 changes: 23 additions & 2 deletions src/objects/token/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,17 @@

@admin.register(Permission)
class PermissionAdmin(admin.ModelAdmin):
list_display = ("token_auth", "object_type", "mode", "use_fields")
list_display = (
"token_auth",
"object_type",
"mode",
"use_fields",
"get_uuid",
)

@admin.display(description="Object type UUID")
def get_uuid(self, obj):
return obj.object_type.uuid

def get_object_fields(self):
object_serializer = ObjectSerializer()
Expand Down Expand Up @@ -103,7 +113,18 @@ def add_view(self, request, form_url="", extra_context=None):

class PermissionInline(EditInlineAdminMixin, admin.TabularInline):
model = Permission
fields = ("object_type", "mode", "use_fields", "fields")
fk_name = "token_auth"
fields = (
"object_type",
"mode",
"use_fields",
"fields",
"get_uuid",
)

@admin.display(description="Object type UUID")
def get_uuid(self, obj):
return obj.object_type.uuid


@admin.register(TokenAuth)
Expand Down

0 comments on commit b4ebbeb

Please sign in to comment.