from django.contrib import admin

from .models import ImageSet, Image


class ImageInline(admin.TabularInline):
    model = Image
    fields = ["image", "preview"]
    readonly_fields = ["preview"]

    def preview(self, obj):
        return "<img src='{}' />".format(obj.small_thumbnail.url)
    preview.allow_tags = True


admin.site.register(
    ImageSet,
    list_display=["primary_image", "created_by", "created_at"],
    raw_id_fields=["created_by"],
    inlines=[ImageInline],
)

from django.contrib import admin

from .models import ImageSet, Image


class ImageInline(admin.TabularInline):
    model = Image
    fields = ["image", "created_by", "preview"]
    readonly_fields = ["preview"]

    def preview(self, obj):
        return "<img src='{}' />".format(obj.small_thumbnail.url)
    preview.allow_tags = True


admin.site.register(
    ImageSet,
    list_display=["primary_image", "created_by", "created_at"],
    raw_id_fields=["created_by"],
    inlines=[ImageInline],
)

Add "created_by" in inline fields
Add "created_by" in inline fields

Image couldn't be added via django admin, simply add "created_by" in inlines fields to make it working.

  from django.contrib import admin
  
  from .models import ImageSet, Image
  
  
  class ImageInline(admin.TabularInline):
      model = Image
-     fields = ["image", "preview"]
+     fields = ["image", "created_by", "preview"]
      readonly_fields = ["preview"]
  
      def preview(self, obj):
          return "<img src='{}' />".format(obj.small_thumbnail.url)
      preview.allow_tags = True
  
  
  admin.site.register(
      ImageSet,
      list_display=["primary_image", "created_by", "created_at"],
      raw_id_fields=["created_by"],
      inlines=[ImageInline],
  )
  
Add "created_by" in inline fields
## Code Before:
from django.contrib import admin

from .models import ImageSet, Image


class ImageInline(admin.TabularInline):
    model = Image
    fields = ["image", "preview"]
    readonly_fields = ["preview"]

    def preview(self, obj):
        return "<img src='{}' />".format(obj.small_thumbnail.url)
    preview.allow_tags = True


admin.site.register(
    ImageSet,
    list_display=["primary_image", "created_by", "created_at"],
    raw_id_fields=["created_by"],
    inlines=[ImageInline],
)

## Instruction:
Add "created_by" in inline fields
## Code After:
from django.contrib import admin

from .models import ImageSet, Image


class ImageInline(admin.TabularInline):
    model = Image
    fields = ["image", "created_by", "preview"]
    readonly_fields = ["preview"]

    def preview(self, obj):
        return "<img src='{}' />".format(obj.small_thumbnail.url)
    preview.allow_tags = True


admin.site.register(
    ImageSet,
    list_display=["primary_image", "created_by", "created_at"],
    raw_id_fields=["created_by"],
    inlines=[ImageInline],
)
