[Answer]-How to create StackedInline in my case?

1👍

The relationship is in the wrong direction to make use of inlines:

# models.py
class Animal(models.Model):
    title = models.CharField(max_length=255)

class Color(models.Model):
    animal = models.ForeignKey(Animal)
    name = models.CharField(null=False, max_length=250)
    other = models.CharField(null=False, max_length=250)

# admin.py
class ColorInline(admin.StackedInline):
    model = Color

class AnimalAdmin(admin.ModelAdmin):
    inlines = [ColorInline, ]

Leave a comment