Opened 4 years ago

Closed 4 years ago

#14340 closed (invalid)

Ordering ModelAdmin form fields

Reported by: humanfromearth Owned by: nobody
Component: contrib.admin Version: 1.2
Severity: Keywords: forms fields
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: UI/UX:


In order to create an custom ordering of ModelAdmin.form fields I had to do something like this:

class my_form(forms.ModelForm):
    def __init__(self, *args, **kwargs):
        super(CandidateAdminForm, self).__init__(*args, **kwargs)
        self.fields = order_fields(self.fields) #Order fields in the desired fashion.

class my_admin(admin.ModelAdmin):
    form = my_form
    exclude=('field1', )
    def declared_fieldsets(self):
        fields = filter(lambda item: item not in self.exclude,
        return ((None, {'fields': fields},),)

I do not think that such a trivial task should go through such a 'hack'. Can someone point out an easier solution to achieve the same thing?

Attachments (0)

Change History (1)

comment:1 Changed 4 years ago by kmtracey

  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset
  • Resolution set to invalid
  • Status changed from new to closed

"How do I?" questions are better asked on #django IRC or django-users; Trac is for bug reports. If simply listing the fields in the desired order in the fields attribute of the ModelAdmin class doesn't accomplish what you want, please follow up with more specifics of why not in one of those other places.

Add Comment

Modify Ticket

Change Properties
<Author field>
as closed
as The resolution will be set. Next status will be 'closed'
The resolution will be deleted. Next status will be 'new'

E-mail address and user name can be saved in the Preferences.

Note: See TracTickets for help on using tickets.