Trying to understand Django Admin a bit better, but I find the Django documentation a bit lacking sometimes (or perhaps my capacity to understand).
I know you can use fieldsets to control the layout of certain admin pages. What I can't seem to grasp is what the fieldset names are.
If I have the following class
class Demo(model.Model):
name = models.CharField(max_length=150)
address = models.CharField(max_length=150)
city = models.CharField(max_length=50)
zip = models.CharField(max_length=15)
and Admin class as the following
class DemoAdmin(admin.ModelAdmin):
list_display = ('name', 'City')
In this, albeit contrived example, what possible fieldsets could I use?
Try this, and you'll soon see how it looks/works.
class DemoAdmin(admin.ModelAdmin):
list_display = ('name', 'city')
fieldsets = (
('Standard info', {
'fields': ('name')
}),
('Address info', {
'fields': ('address', ('city', 'zip'))
}),
)
When you go to the change-page to edit, you'll get one box "standard info" with the name-box. And you'll get another box that says "address info" with the adress field first, and then the city and zip-fields on the same line after.
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