1

I want to try to add a ListField increasible on django admin. I discover I can do that with inlines, so I goes to the doc to find this code :

models.py

from django.db import models

class Author(models.Model):
   name = models.CharField(max_length=100)

class Book(models.Model):
   author = models.ForeignKey(Author, on_delete=models.CASCADE)
   title = models.CharField(max_length=100)

admin.py

class BookInline(admin.TabularInline):
    model = Book

class AuthorAdmin(admin.ModelAdmin):
    inlines = [
        BookInline,
    ]

I simply copy this code to see how it render on Django admin page. But the following error appear :

<class 'users.admin.BookInline'>: (admin.E202) 'users.Book' has no ForeignKey to 'users.Book'.

I don't understand why because Book as a ForeignKey. Am I missing something ?

Thx

Dad95
  • 11
  • 2

0 Answers0