Question

According to the docs:

http://django-grappelli.readthedocs.org/en/latest/customization.html#rearrange-inlines

The two classes for the placeholder are important. First, you need a class placeholder. The second class has to match the id of the inline–group.

All's well and good, I was able to set up my inlines fine, my issue is now - where does grappelli get the "id of the inline group" I can't find any reference, and pouring through the source code is offering me no solace.

Simply, I want to change the element-id that grappelli is using. Currently, it looks to me that it is taking the object name itself and converting to a lowercase name and appending set to the end. Do we have access to override the "id of the inline-group"?

Also, I am not 100% sure exactly how (or where) grappelli is doing this, it is definitely not documented... at all in fact.

Any help would be much appreciated.

Était-ce utile?

La solution

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".

Autres conseils

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.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top