L
L
Lopus2016-05-05 15:58:22
Django
Lopus, 2016-05-05 15:58:22

How to specify all fields in fields or fieldsets?

I want to combine two fields in the admin panel into fieldsets, but then I have to list all the fields in the first block. And for a model with a large number of fields, this is not desirable at all.
For example, to not list fields ('url', 'title', 'content', 'sites') as in the example:

fieldsets = (
        (None, {
            'fields': ('url', 'title', 'content', 'sites')
        }),
        ('Advanced options', {
            'classes': ('collapse',),
            'fields': ('registration_required', 'template_name'),
        }),
    )

django 1.9.5

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Anatoly Scherbakov, 2016-05-05
@Altaisoft

This cannot be done with built-in methods, as far as I know. You can override the method Model.get_fieldsets, which will receive a list of all fields from the model class and form what you need - but this is too perverse in my opinion.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question