I have a Django model layout that looks something like this:
class Author(models.Model):
name = models.CharField(max_length=50, unique=True)
class Publication(models.Model):
author = models.ForeignKey(Author)
#Some shared fields
class Meta:
abstract = True
class Book(Publication):
#Book specific fields
class Poem(Publication):
#Poem specific fields
Generally speaking, I'd like to show information listed by author and sorted by some information, like pub_date, so that the end user would see something like:
Author A:
Author B:
And so on. I can figure out how to display these on the front-end (I can either use django-polymorphic or simply combine the author.book_set.all() and author.poem_set.all() into a single list and sort). But I CANNOT figure out how to implement this in the Admin site. I would like the structure to be exactly the same as above -- so that when I click on Author A I'd get:
If I simply attach Poem and Book as TabularInlines, they would be separated out into separate fieldsets, like so:
inline for Poem 3
inline for Book 1
But I think it's important for functionality that they are mixed together in a single fieldset (with the fields specific to the other child class either grayed out or not present for each inline). Does anyone have any idea how to implement this?
Well, it didn't seem like there was a simple way to do this, so I delved into django.contrib a bit and built an app for handling this: Django Merged Inlines. If it would be useful to anyone, it's available here:
https://github.com/MattBroach/Django-Merged-Inlines
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With