Skip to content

Instantly share code, notes, and snippets.

@Scorpil
Created December 24, 2012 10:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Scorpil/4368744 to your computer and use it in GitHub Desktop.
Save Scorpil/4368744 to your computer and use it in GitHub Desktop.

When you have redefined ModelAdmin and redefined ModelForm for change_view/add_view, this form will be modified to AdminForm. In process, django will automatically create fieldset, if it's not already there, by calling get_fieldset (django.contrib.admin.options.py:425):

def get_fieldsets(self, request, obj=None):
    "Hook for specifying fieldsets for the add form."
    if self.declared_fieldsets:
        return self.declared_fieldsets
    form = self.get_form(request, obj)
    fields = list(form.base_fields) + list(self.get_readonly_fields(request, obj))
    return [(None, {'fields': fields})]

Obviously, this won't preserve any ordering that may have been specified in self.fields.keyOrder. I understand why this was implemented in such a way: keyOrder is specified (in most cases) when form is initialized, and AdminForm is created before that, but it would be great to have ordering functionality in place for django-admin, so i propose to think about the good way to fix this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment