Add redir model, remove children albums
This commit is contained in:
parent
684982eca5
commit
1dbd1c1779
9 changed files with 84 additions and 23 deletions
|
@ -5,7 +5,7 @@ from imagekit.admin import AdminThumbnail
|
|||
from imagekit.cachefiles import ImageCacheFile
|
||||
from imagekit.processors import ResizeToFit
|
||||
|
||||
from gallery.models import Album, City, Location, Photo
|
||||
from gallery.models import Album, City, Location, Photo, Redir
|
||||
|
||||
|
||||
class AdminThumbnailSpec(ImageSpec):
|
||||
|
@ -20,6 +20,26 @@ def cached_admin_thumb(instance):
|
|||
return cached
|
||||
|
||||
|
||||
class RedirAdmin(admin.ModelAdmin):
|
||||
list_display = ('path', 'album', 'test_url')
|
||||
search_fields = ('path',)
|
||||
ordering = ('path',)
|
||||
list_per_page = 10
|
||||
list_editable = ('album',)
|
||||
|
||||
def formfield_for_foreignkey(self, db_field, request, **kwargs):
|
||||
if db_field.name == "album":
|
||||
kwargs["queryset"] = Album.objects.all().order_by('name') # Järjestä albumit aakkosjärjestykseen
|
||||
return super().formfield_for_foreignkey(db_field, request, **kwargs)
|
||||
|
||||
def test_url(self, obj):
|
||||
return format_html(
|
||||
'<a href="/{}" target="_blank">http://nyymix.net/{}</a>',
|
||||
obj.path, obj.path
|
||||
)
|
||||
test_url.short_description = "Test redirection"
|
||||
|
||||
|
||||
class CityAdmin(admin.ModelAdmin):
|
||||
list_display = ('name',)
|
||||
search_fields = ('name',)
|
||||
|
@ -37,39 +57,53 @@ class LocationAdmin(admin.ModelAdmin):
|
|||
|
||||
class AlbumAdmin(admin.ModelAdmin):
|
||||
prepopulated_fields = {'slug': ('name',)}
|
||||
list_display = ('__str__', 'location', 'album_date', 'is_public', 'thumbnail', )
|
||||
list_display = ('__str__', 'name', 'location', 'album_date', 'is_public', 'thumbnail', )
|
||||
search_fields = ('name',)
|
||||
ordering = ('-album_date',)
|
||||
list_per_page = 30
|
||||
list_editable = ('is_public', 'location')
|
||||
list_per_page = 20
|
||||
list_editable = ('name', 'is_public', 'location')
|
||||
readonly_fields = ['cover_preview'] # Lisätään esikatselukuva readonly_fieldsiin
|
||||
|
||||
def cover_preview(self, obj):
|
||||
if obj.cover and obj.cover.photo:
|
||||
return format_html(
|
||||
'<img src="{}" style="max-width: 300px; height: auto;"/>',
|
||||
obj.cover.photo.url,
|
||||
)
|
||||
return "No cover image available"
|
||||
cover_preview.short_description = "Cover Preview"
|
||||
|
||||
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;"/>',
|
||||
'<img src="{}" style="width: 50px; height: auto;"/>',
|
||||
obj.cover.photo.url,
|
||||
)
|
||||
return "-"
|
||||
thumbnail.short_description = "Thumbnail"
|
||||
|
||||
|
||||
|
||||
class PhotoAdmin(admin.ModelAdmin):
|
||||
list_display = ('slug', 'album', 'admin_thumbnail',)
|
||||
list_display = ('slug', 'album', 'is_favorite', 'admin_thumbnail',)
|
||||
list_display_links = ('slug',)
|
||||
search_fields = ('slug',)
|
||||
search_fields = ('slug', 'photo',)
|
||||
readonly_fields = ['slug', 'taken_at', 'height', 'width', 'exif', ]
|
||||
admin_thumbnail = AdminThumbnail(image_field=cached_admin_thumb)
|
||||
list_filter = ('album',)
|
||||
list_per_page = 30
|
||||
list_editable = ('is_favorite',)
|
||||
|
||||
|
||||
admin.site.register(City, CityAdmin)
|
||||
admin.site.register(Location, LocationAdmin)
|
||||
admin.site.register(Album, AlbumAdmin)
|
||||
admin.site.register(Photo, PhotoAdmin)
|
||||
admin.site.register(Redir, RedirAdmin)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue