vladimir.gorea
vladimir.gorea

Reputation: 661

Django 1.11 - Inline Admin Model - Error: admin.E106

I want to access the Image model in the Art admin page as it's written in the docs but something goes wrong:

/gallery/models.py:

class Image:
    name = models.CharField(max_length=256)
    thumb = models.CharField(max_length=256)
    product = models.ForeignKey(Art, on_delete=models.CASCADE, related_name='images')

/product/admin.py:

class ArtImage(admin.TabularInline):
    model = Image
    extra = 3

class ArtAdmin(admin.ModelAdmin):
    inlines = [ArtImage]

admin.site.register(Art, ArtAdmin)

When I apply the makemigrations command I get

SystemCheckError: System check identified some issues: ERRORS: : (admin.E106) The value of 'product.admin.ArtImage.model' must be a Model.

What could it be?

Upvotes: 0

Views: 1026

Answers (2)

mtbno
mtbno

Reputation: 598

In my case I just accidentally left a trailing comma when defining the inline:

class PhotoInline(admin.TabularInline):
    model = Photo, # <-- watch out for the comma
    extra = 0

Upvotes: 0

vladimir.gorea
vladimir.gorea

Reputation: 661

As I was pointed out by Alasdair in the comment, I forgot to extend the models.Model when writing the Image class, that's why it wasn't being recognised as a Model instance.

The Image class should look like this:

class Image(models.Model):
    name = models.CharField(max_length=256)
    thumb = models.CharField(max_length=256)
    product = models.ForeignKey(Art, on_delete=models.CASCADE, related_name='images')

Piece of advice: don't code when tired, you make silly mistakes

Upvotes: 1

Related Questions