Is it possible to display a model's related child rows using the Django admin interface? An example model:
def Parent(models.Model):
name = models.TextField()
....
def Child(models.Model):
name = models.TextField()
Parent = models.ForeignKey(Parent)
...
In the admin interface, when viewing a particular Parent object might display something like:
Name: Jack
Children:
Bob
Jenny
Sam
....
I understand that I can extend the admin views manually, just wondering if there's a bit of magic that I can add to my admin.py file instead.
One of the most powerful parts of Django is the automatic admin interface. It reads metadata from your models to provide a quick, model-centric interface where trusted users can manage content on your site. The admin's recommended use is limited to an organization's internal management tool.
To login to the site, open the /admin URL (e.g. http://127.0.0.1:8000/admin ) and enter your new superuser userid and password credentials (you'll be redirected to the login page, and then back to the /admin URL after you've entered your details).
In this article, we will discuss how to enhance Django-admin Interface. Let us create an app called state which has one model with the same name(state). When we register app to admin.py it shows like. Now lets' customize django admin according to available options.
You could add the child objects as inlines.
class ChildInline(admin.TabularInline):
model = Child
class ParentAdmin(admin.ModelAdmin):
inlines = [
ChildInline,
]
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