Add some admin useful informations and SQL optimisation
This commit is contained in:
parent
71066e5507
commit
bc58031125
1 changed files with 18 additions and 1 deletions
|
|
@ -25,6 +25,11 @@ class GalleryAdmin(admin.ModelAdmin):
|
||||||
|
|
||||||
get_tags.short_description = _("tags")
|
get_tags.short_description = _("tags")
|
||||||
|
|
||||||
|
def get_queryset(self, request):
|
||||||
|
# Cette étape est correcte et essentielle
|
||||||
|
return super().get_queryset(request).prefetch_related("tags")
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class PhotoAdmin(admin.ModelAdmin):
|
class PhotoAdmin(admin.ModelAdmin):
|
||||||
list_display = (
|
list_display = (
|
||||||
|
|
@ -35,8 +40,9 @@ class PhotoAdmin(admin.ModelAdmin):
|
||||||
"view_count",
|
"view_count",
|
||||||
"admin_thumbnail",
|
"admin_thumbnail",
|
||||||
"get_owner",
|
"get_owner",
|
||||||
|
"get_galleries"
|
||||||
)
|
)
|
||||||
list_filter = ["date_added", "is_public", "owner"]
|
list_filter = ["date_added", "is_public", "owner","galleries"]
|
||||||
search_fields = ["title", "slug", "caption"]
|
search_fields = ["title", "slug", "caption"]
|
||||||
list_per_page = 25
|
list_per_page = 25
|
||||||
prepopulated_fields = {"slug": ("title",)}
|
prepopulated_fields = {"slug": ("title",)}
|
||||||
|
|
@ -45,6 +51,17 @@ class PhotoAdmin(admin.ModelAdmin):
|
||||||
|
|
||||||
def get_owner(self, obj):
|
def get_owner(self, obj):
|
||||||
return obj.owner.username
|
return obj.owner.username
|
||||||
|
|
||||||
|
|
||||||
|
def get_queryset(self, request):
|
||||||
|
# Précharge les objets 'galleries' en une seule requête supplémentaire
|
||||||
|
return super().get_queryset(request).prefetch_related("owner",'galleries')
|
||||||
|
|
||||||
|
def get_galleries(self, obj):
|
||||||
|
return ", ".join([g.title for g in obj.galleries.all()])## get all linked galeries
|
||||||
|
|
||||||
|
get_galleries.short_description = _("Gallery")
|
||||||
|
get_galleries.admin_order_field = 'galleries__title'
|
||||||
|
|
||||||
get_owner.admin_order_field = "owner"
|
get_owner.admin_order_field = "owner"
|
||||||
get_owner.short_description = _("owner")
|
get_owner.short_description = _("owner")
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue