[Answered ]-Django Grappelli Rearrange Inlines id override

2đź‘Ť

âś…

It is the id of the inline element on HTML page. You can check the id of the default HTML inline element.

 <div id="[related_name of ForeignKey]-group">

For example:
If in model “MyModel2”, you have a ForeignKey like this:

my_model_1 = models.ForeignKey(MyModel1, related_name='my_model_2')

Then the id should be “my_model_2-group”.

👤feng han

0đź‘Ť

The id of the inline group is set in grappelli/templates/admin/edit_inline, in stacked.html line 5, or tabular.html line 6 (depending on which type of inline you’re usng):

id="{{ inline_admin_formset.formset.prefix }}-group" >

You can override this by copying the file (stacked.html or tabular.html) into your template directory and setting the variable “template” to the file’s new location e.g.:

# admin.py

class MyModelInline(admin.StackedInline):
    template = 'path/to/stacked.html'
    ...

Then edit whatever you want in e.g. stacked.html.

I don’t know if this is the best-practices way of doing this, but it’s similar to what’s done in the django tutorial.

👤dangerdak

Leave a comment