I am using this blog: https://medium.com/@adriennedomingus/adding-custom-views-or-templates-to-django-admin-740640cc6d42
Unable to make a custom template view in the Django Admin. I am getting django.core.exceptions.AppRegistryNotReady: Apps aren't loaded yet
If I comment out the app in the settings.py, I get error admin.site.register(Template, TemplateAdmin) NameError: name 'Template' is not defined.
If I import the Template from django.templates then I get TypeError: 'type' object is not iterable
Unable to do: 1) custom_admin_site.register & 2) models.Template is not found. Says there is no Template in models.
I have this on admin.py:
from django.contrib import admin
from django.db import models
from django.templates import Template
class TemplateAdmin(admin.ModelAdmin):
change_form_template = ‘admin/test_attempt.html’
admin.site.register(Template, TemplateAdmin)
if I register with CustomAdminSite then I get register for model in model_or_iterable: TypeError: 'MediaDefiningClass' object is not iterable error:
CustomAdminSite.register(Template, TemplateAdmin)
# Even the following doesnot work
# custom_site_admin.register(Template, TemplateAdmin)
I have this on views.py:
from django.shortcuts import render
from django.http import HttpResponse
from django.template import loader
def preview(self, request, object_id):
context = {}
context = {
**self.each_context(request),
'title': self.index_title,
# Unable to get this app_list as well
# 'app_list': app_list,
}
request.current_app = self.name
#load_template = request.path.split('/')[-1]
#template = loader.get_template('admin/' + load_template)
template = loader.get_template('admin/test_attempt.html')
return HttpResponse(template.render(context, request))
I have this on urls.py:
from .views import preview
class CustomAdminSite(admin.AdminSite):
def get_urls(self):
urls = super(CustomAdminSite, self).get_urls()
custom_urls = [
path(r’^admin/test/(?P<object_id>\d+)$’, self.admin_view(preview), name=”preview”),
]
return urls + custom_urls
I have this on my apps.py:
class CustomAdminSiteConfig(AdminConfig):
default_site = 'batchexits.admin.CustomAdminSite'
I have added this in my settings.py registered apps:
'batchexits.admin.CustomAdminSiteConfig',
I have read this: how to fix django admin "You don't have permission to view or edit anything."?
Any help to get this working is appreciated.