Add some admin useful informations and SQL optimisation
This commit is contained in:
parent
c4278ec85e
commit
9020074df8
3 changed files with 19 additions and 4 deletions
|
|
@ -28,7 +28,7 @@ BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
|
||||||
SECRET_KEY = "CHANGE ME"
|
SECRET_KEY = "CHANGE ME"
|
||||||
|
|
||||||
# SECURITY WARNING: don't run with debug turned on in production!
|
# SECURITY WARNING: don't run with debug turned on in production!
|
||||||
DEBUG = False
|
DEBUG = True
|
||||||
|
|
||||||
ALLOWED_HOSTS = [
|
ALLOWED_HOSTS = [
|
||||||
"127.0.0.1",
|
"127.0.0.1",
|
||||||
|
|
|
||||||
|
|
@ -25,6 +25,10 @@ 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 +39,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",)}
|
||||||
|
|
@ -46,6 +51,16 @@ 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")
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -15,7 +15,7 @@ from django.conf import settings
|
||||||
from django.core.exceptions import ValidationError
|
from django.core.exceptions import ValidationError
|
||||||
from django.core.files.base import ContentFile
|
from django.core.files.base import ContentFile
|
||||||
from django.core.validators import RegexValidator
|
from django.core.validators import RegexValidator
|
||||||
from django.core.cache import caches
|
from django.core.cache import cache
|
||||||
from django.db import models
|
from django.db import models
|
||||||
from django.template.defaultfilters import slugify
|
from django.template.defaultfilters import slugify
|
||||||
from django.urls import reverse
|
from django.urls import reverse
|
||||||
|
|
@ -25,7 +25,7 @@ from django.utils.timezone import now
|
||||||
from django.utils.translation import gettext_lazy as _
|
from django.utils.translation import gettext_lazy as _
|
||||||
from PIL import Image, ImageFile, ImageFilter
|
from PIL import Image, ImageFile, ImageFilter
|
||||||
|
|
||||||
|
caches = cache
|
||||||
|
|
||||||
logger = logging.getLogger("photologue.models")
|
logger = logging.getLogger("photologue.models")
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue