Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Django admin display groups horizontally

How do I get Django admin to display groups horizontally? If I have 3 adjacent datetime fields, I'd rather them take up 1 row, not 3.

like image 323
josh Avatar asked Apr 21 '09 19:04

josh


3 Answers

Have you tried grouping your fieldsets into tuples?:

fieldsets = (
        (None, {
            'fields': ('name','description',('start_date','end_date'), 'location', ('latitude','longitude'))
        }),
    )
like image 85
Andy Baker Avatar answered Oct 31 '22 21:10

Andy Baker


The way I've done it is to make a custom admin template. You can just take the one that comes with django, copy it, and edit the parts you want changed.

A good tutorial on how to do that is on the django site. Specifically, there is a part on making a custom admin template.

like image 23
landyman Avatar answered Oct 31 '22 22:10

landyman


It is been tested on Django==2.0.7 and worked like a charm, a really important piece of advice regarding the use of the param "fieldsets" is that u cant use "fields" property at same time , otherwise u will get the following error on ur console :

(admin.E005) Both 'fieldsets' and 'fields' are specified.

The syntax would be smth like these :

fieldsets = (
    ('General Information', {
        'fields': (
            ("id", "created_at", "updated_at",),
            ("name", "coupon_type", "discount", "is_active",),
            ("quantity", "minumum_quantity", "before_expire",),
        ),
    }),
    ('Expiration Dates', {
        'fields': (
            ("expiration_from", "expiration_to",),
        ),
    }),
    ('Grants for', {
        'fields': (
            "products", "campaigns_product", "sellers", "platforms",
        ),
    }),
)
like image 1
Manuel Lazo Avatar answered Oct 31 '22 21:10

Manuel Lazo