Add likes, update templates
This commit is contained in:
parent
89134993ad
commit
f3a94857d0
8 changed files with 109 additions and 16 deletions
|
@ -1,4 +1,5 @@
|
|||
from django.contrib import admin
|
||||
from django.utils.html import format_html
|
||||
from imagekit import ImageSpec
|
||||
from imagekit.admin import AdminThumbnail
|
||||
from imagekit.cachefiles import ImageCacheFile
|
||||
|
@ -36,16 +37,34 @@ class LocationAdmin(admin.ModelAdmin):
|
|||
|
||||
class AlbumAdmin(admin.ModelAdmin):
|
||||
prepopulated_fields = {'slug': ('name',)}
|
||||
list_display = ('__str__', 'location', 'album_date', 'is_public', )
|
||||
list_display = ('__str__', 'location', 'album_date', 'is_public', 'thumbnail', )
|
||||
search_fields = ('name',)
|
||||
ordering = ('name',)
|
||||
list_per_page = 30
|
||||
list_editable = ('is_public', 'location')
|
||||
|
||||
def formfield_for_foreignkey(self, db_field, request, **kwargs):
|
||||
if db_field.name == "cover":
|
||||
if hasattr(request, 'resolver_match') and request.resolver_match.kwargs.get('object_id'):
|
||||
album_id = request.resolver_match.kwargs['object_id']
|
||||
kwargs["queryset"] = Photo.objects.filter(album_id=album_id)
|
||||
return super().formfield_for_foreignkey(db_field, request, **kwargs)
|
||||
|
||||
def thumbnail(self, obj):
|
||||
if obj.cover and obj.cover.photo:
|
||||
return format_html(
|
||||
'<img src="{}" style="width: 50px; height: 50px; object-fit: cover;"/>',
|
||||
obj.cover.photo.url,
|
||||
)
|
||||
return "-"
|
||||
thumbnail.short_description = "Thumbnail"
|
||||
|
||||
|
||||
|
||||
class PhotoAdmin(admin.ModelAdmin):
|
||||
list_display = ('slug', 'album', 'admin_thumbnail',)
|
||||
list_display_links = ('slug',)
|
||||
search_fields = ('slug',)
|
||||
readonly_fields = ['slug', 'taken_at', 'height', 'width', 'exif', ]
|
||||
admin_thumbnail = AdminThumbnail(image_field=cached_admin_thumb)
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue