Why does Django Admin shows empty dropdown on foreign key field to multi-inheritance model?

640 views Asked by At

I have the following models:

class BaseModel(models.Model):
    id = models.UUIDField(primary_key=True, default=uuid.uuid4, editable=False)

    class Meta:
        abstract = True

class Content(BaseModel):
    title = models.CharField(max_length=2000)

class Document(Content):
    file = models.FileField()
    reading_time = models.IntegerField()

class DocumentView(BaseModel):
    document = models.ForeignKey(Document, on_delete=models.CASCADE)
    viewed_on = models.DateTimeField(auto_now=True)

Everything works as expected, except that in the Django Admin, editing a DocumentView model, the Document dropdown doesn't get selected with the saved Document.

Regarding the Admin, I use it in the default way:

admin.site.register(DocumentView)

Here's a screenshot: enter image description here

0

There are 0 answers