djangodjango-templatesdjango-adminphotologue

How to keep using 3rd app admin templates after customizations of admin.py?


I use django-photologue and extended it:

# gallery.models.py
from photologue.models import Photo
from profiles.models import UserProfile

class PhotoExtended(Photo):
    user = models.ForeignKey(UserProfile, verbose_name=_('user'), on_delete=models.CASCADE)

# gallery.admin.py
from photologue.admin import PhotoAdmin as PhotoAdminDefault
from photologue.models import Photo

from .models import PhotoExtended

class PhotoAdmin(PhotoAdminDefault):
    save_on_top = True

admin.site.unregister(Photo)
admin.site.register(PhotoExtended, PhotoAdmin)

Photologue has a feature to upload zip file with photos and it can be done using additional button in admin. After my changes this button disappeared.

Is it possible to use native photologues admin templates in order to avoid copy-pasting them to my app's template folder? In INSTALLED_APPS photologue is higher than my gallery app

Here there are the photologues admin templates.


Solution

  • In the path templates/admin/photologue/photo/change_list.htmlthe part photo corresponds to the Photo model. You subclassed that model. The new model name is PhotoExtended but there is no template in templates/admin/photologue/photo_extend/change_list.html.

    Copy the change_list.html from photologue app into your own (app) template folder. Eg: project/app/templates/admin/photologue/photo_extend/change_list.html.

    Alternatively you can also just create a new file and use include the old template:

    # project/app/templates/admin/photologue/photo_extend/change_list.html
    {% include 'admin/photologue/photo/change_list.html' %}
    

    Update: Another alternative is to set (one of) the BaseModelAdmin properties:

    # Custom templates (designed to be over-ridden in subclasses)
    add_form_template = None
    change_form_template = None
    change_list_template = None
    delete_confirmation_template = None
    delete_selected_confirmation_template = None
    object_history_template = None