Django Admin & # 8594; Reorder fields, including built-in fields

I have a Man model that has a one-to-many relationship with other models, such as Address. I want to edit these models on the same page as Person, which I can already do with the built-in lines. But I also want to reorder the fields.

I want the (inline) Address field to be the third item in the list, but for

('first_name', 'last_name', 'Adress_Inline', 'nationality', etc.) I get this: PersonAdmin.fields' refers to the field 'Address_Inline' that is not on the form.

Is there a way to reorder fields and get specific inline fields between the "regular" Model fields?

Thanks!

+7
django-models django-admin django-forms
source share
4 answers

You will have to manually expand the admin template (change_form.html) and the positions of the hard code in it. AFAIK, you cannot embed inline forms in the middle of the parent form.

0
source share

You can do this with javascript. You need to override the template and possibly add a div tag. Then copy your div you want to copy, and then hide the original div (with inline). Hope this helps.

0
source share

Whenever Django creates an admin form template, the list of inline fields is available in the {{inline_admin_formset}} variable, you can use this to display inline fields anywhere in your own custom change_form.html template.

You must expand the change_form.html template to do this, there will be no other way.

0
source share

Custom django fields for determining the order of fields for viewing and adding / editing views of an object.

class YourCustomClass(admin.ModelAdmin): models = Your_Model fieldsets = ((None, {'fields': ('image', 'name',)}),) add_fieldsets = ((None, {'fields': ('name', 'image',)}),) 
0
source share

All Articles