Opened 14 years ago
Closed 14 years ago
#14340 closed (invalid)
Ordering ModelAdmin form fields
Reported by: | Alexandru Plugaru | 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: | no | UI/UX: | no |
Description
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', ) @property def declared_fieldsets(self): fields = filter(lambda item: item not in self.exclude, self.form().fields.keys()) 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?
Note:
See TracTickets
for help on using tickets.
"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.