views:

640

answers:

1

Hi

Trying to undertstand 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 cant seem to grasp is what the fieldset names are.

If i have the following class

Clas 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 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?

Thanks

+1  A: 

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.

Velmont
Thanks, giving it a whirl!
Consiglieri