33from django .contrib import admin
44from django .utils .html import format_html
55from django .utils .safestring import mark_safe
6+ from imagekit .admin import AdminThumbnail
67from nested_admin .nested import NestedModelAdmin
78from pygments import highlight
89from pygments .formatters import HtmlFormatter
@@ -19,32 +20,26 @@ class m2mPhotoAdminInlineMixin:
1920 can_delete = False
2021 fields = [
2122 "photo" ,
22- "preview " ,
23+ "image_thumbnail " ,
2324 ]
2425 readonly_fields = [
25- "preview " ,
26+ "image_thumbnail " ,
2627 ]
2728
28- def preview (self , obj ):
29- if not obj ._state .adding :
30- return format_html (f"<img src='{ obj .photo .image .url } ' height='150' />" )
31- return "Upload image for preview"
29+ image_thumbnail = AdminThumbnail (image_field = lambda obj : obj .photo .thumbnail )
3230
3331
3432@admin .register (Photo )
3533class PhotoAdmin (NestedModelAdmin ):
36- list_display = ("__str__" , "user" , "created_at" , "preview " )
34+ list_display = ("__str__" , "user" , "created_at" , "image_thumbnail " )
3735 list_filter = ("user" , "created_at" )
38- fields = ("created_at" , ("image" , "preview " ))
39- readonly_fields = ("preview " , "created_at" )
36+ fields = ("created_at" , ("image" , "image_thumbnail " ))
37+ readonly_fields = ("image_thumbnail " , "created_at" )
4038 list_per_page = 10
4139
42- inlines = [ FlaggedContentNestedInlineAdmin , PhotoIdentificationTaskAdminInline ]
40+ image_thumbnail = AdminThumbnail ( image_field = "thumbnail" )
4341
44- def preview (self , obj ):
45- if not obj ._state .adding :
46- return format_html (f"<img src='{ obj .image .url } ' height='150' />" )
47- return "Upload image for preview"
42+ inlines = [FlaggedContentNestedInlineAdmin , PhotoIdentificationTaskAdminInline ]
4843
4944 @admin .display (description = "EXIF" )
5045 def exif_dict (self , obj ):
0 commit comments