Skip to content

Commit

Permalink
Deleted user object references, refactor the orden fields & added pic…
Browse files Browse the repository at this point in the history
…ture_url property
  • Loading branch information
Fer-Bar committed May 23, 2024
1 parent f3cc2d1 commit 6ea8408
Showing 1 changed file with 15 additions and 22 deletions.
37 changes: 15 additions & 22 deletions people/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,34 +25,30 @@ class BasePersonAdmin(ModelAdmin):
"user__email",
]
autocomplete_fields = [
"user",
"occupation",
"city",
"nationality",
]

def picture_display(self, obj=None):
return mark_safe(f'<img src="{obj.picture.url}" height=250>')
return mark_safe(
f'<img style="object-fit: cover;" src="{obj.picture_url}" height=250 width=100%>'
)

picture_display.short_description = _("See picture")
picture_display.short_description = _("Profile Picture")

def get_readonly_fields(self, request, obj=None):
return ["picture_display",]
readonly_fields = ("picture_display",)

def get_fieldsets(self, request, obj=None):
if obj is None or not obj.picture:
main_fields = [
("picture",),
("first_name", "last_name", "gender"),
]
else:
main_fields = [
(
"picture_display",
"picture",
"first_name",
"last_name",
"gender",
),
]

Expand All @@ -62,7 +58,7 @@ def get_fieldsets(self, request, obj=None):
{
"fields": main_fields
+ [
("city",),
("first_name", "last_name", "gender", "city"),
("personal_email", "birthday"),
]
},
Expand All @@ -74,10 +70,10 @@ def get_fieldsets(self, request, obj=None):
("document_type", "document_id"),
("marital_status",),
("phone_number", "secondary_phone_number"),
("nationality", ),
("address", ),
("neighborhood", ),
("occupation", ),
("nationality",),
("address",),
("neighborhood",),
("occupation",),
]
},
),
Expand All @@ -86,20 +82,17 @@ def get_fieldsets(self, request, obj=None):

@admin.register(Person)
class PersonAdmin(BasePersonAdmin):

def get_fieldsets(self, request, obj=None):
fieldsets = super().get_fieldsets(request, obj=obj)
return fieldsets
list_display = ["first_name", "last_name", "list_pets",]
inlines = [
PetInline,
]

def has_delete_permission(
self, request, obj=None
): # This allows to delete only if you're a superuser
return request.user.is_superuser and request.user.is_active

inlines = [PetInline,]
list_display = ["first_name", "last_name", "list_pets"]

def list_pets(self, obj):
return ", ".join([str(pet) for pet in obj.pets.all()])

list_pets.short_description = _("Pets")
list_pets.short_description = _("My Pets")

0 comments on commit 6ea8408

Please sign in to comment.