1

I am trying to override change_form.html only for one model, so I did as explained in the django documentation and created /templates/my_app_name/my_model_name/change_form.html.

The problem is, it is not working and I am not seeing the extra features that I have added to the change_form template. I am using django_guardian, which also overrides the same template, so my assumption is that this is causing the issue. It is worth mentioning, that before placing the template in the my_app_name/my_model_name/ folder, the features of both templates were visible in the admin interface.

Is there a way to apply this only for 1 model?

dsax7
  • 1,333
  • 22
  • 36

2 Answers2

2

You should check this answer.

You can specify which template to extend in your template. So you're extending third app's template which extends djando admin's template.

Example:

admin.py

class MyModel(ThirdAppModelAdmin):
    change_form_template = 'my_app_name/templates/change_form.html'

my_app_name/templates/change_form.html

{% extends "thirdapp/templates/change_form.html" %}
{% block thatYouNeed %}
    {{ block.super }}
    Your content here
{% endblock %}

Well, at least this is how I managed to do that.

Artem Ilin
  • 353
  • 2
  • 19
1

The GuardedModelAdmin changes change_form_template to use the template from django-guardian. Try changing it back in your model admin class:

class MyModelAdmin(GuardedModelAdmin):
    ...
    change_form_template = 'my_app_name/my_model_name/change_form.html'
Alasdair
  • 298,606
  • 55
  • 578
  • 516