2

I was using Django import-export app and now I want to add Grappelli in order to improve the Admin interface. I'm getting an error related to the templates. Any suggestion to get them work together?

Error:

Environment:


Request Method: GET
Request URL: http://localhost:8000/admin/db_personal/personalinstituto/

Django Version: 1.7c1
Python Version: 2.7.8
Installed Applications:
('grappelli',
 'django.contrib.admin',
 'django.contrib.auth',
 'django.contrib.contenttypes',
 'django.contrib.sessions',
 'django.contrib.messages',
 'django.contrib.staticfiles',
 'import_export',
 'db_personal')
Installed Middleware:
('django.contrib.sessions.middleware.SessionMiddleware',
 'django.middleware.common.CommonMiddleware',
 'django.middleware.csrf.CsrfViewMiddleware',
 'django.contrib.auth.middleware.AuthenticationMiddleware',
 'django.contrib.auth.middleware.SessionAuthenticationMiddleware',
 'django.contrib.messages.middleware.MessageMiddleware',
 'django.middleware.clickjacking.XFrameOptionsMiddleware')


Template error:
In template C:\Gestion AI2\web_nueva\templates\admin\change_list.html, error at line 1
   maximum recursion depth exceeded in __instancecheck__
   1 :  {% extends "admin/change_list.html" %} 


   2 : 


   3 : {# Original template renders object-tools only when has_add_permission is True. #}


   4 : {# This hack allows sub templates to add to object-tools #}


   5 : {% block object-tools %}


   6 :   <ul class="object-tools">


   7 :     {% block object-tools-items %}


   8 :       {% if has_add_permission %}


   9 :         {{ block.super }}


   10 :       {% endif %}


   11 :     {% endblock %}
loar
  • 1,505
  • 1
  • 15
  • 34
  • Here a solution: https://github.com/bmihelac/django-import-export/issues/38 But there's still a problem in how are showed the buttons Import, Export and Add because are hidden (are located between the word admin and Filter): https://dl.dropboxusercontent.com/u/23171086/image.png – loar Jan 28 '15 at 12:26
  • grappelli needs to be before import_export within INSTALLED_APPS. I have added an answer as well below – Shrey Mar 05 '20 at 08:41

4 Answers4

1

Well, i think your problem is not in the template script but the extend. Your template tries to extend itself.

templates\admin\change_list.html, error at line 1 1 : {% extends "admin/change_list.html" %}

admin/change_list.html refers to the basic django template change_list. It seems that your django-import-export change_list template has the same path. Your change_list template from django-import-export should be in template/admin/import_export/change_list.html

jcs
  • 426
  • 3
  • 14
  • I've copied the change_list.html from import-export to C:\Gestion AI2\web_nueva\templates\admin\import_export/change_list.html but nothing changes. Should I change the extends as well? – loar Apr 14 '15 at 08:15
  • @Alex_Loar Sorry it is not what i meant you to do. I am a bit confused. What app is this directory C:\Gestion AI2\web_nueva\templates\ from ? grappelli or import-export? Your error shows import-export change_list.html script. So I first thought the directory (...web_nueva\templates\) was import-export but now I am not sure anymore. – jcs Apr 14 '15 at 15:40
0

I use them together fine. I had to change this in admin/includes_grappelli/header.html :

-                    {% url admin:password_change as password_change_url %}
+                    {% url 'admin:password_change' as password_change_url %}

-                    {% url admin:logout as logout_url %}
+                    {% url 'admin:logout' as logout_url %}

-                {% url test-index as testindexurl %}
+                {% url 'test-index' as testindexurl %}

-                {% url django-admindocs-docroot as docsroot %}
+                {% url 'django-admindocs-docroot' as docsroot %}

And call it with ImportExportActionModelAdmin to avoid CSS problems.

from import_export.admin import ImportExportActionModelAdmin

class MyModelAdmin(ImportExportActionModelAdmin):
    """
    Admin class for MyModel model
    """
    form = MyModelAdminForm

    list_display = ()
    ordering = []

    resource_class = MyModelResource

Hope it helps...

HydrUra
  • 1,336
  • 2
  • 13
  • 23
  • I can't find the header.html :( – loar Mar 06 '15 at 10:36
  • Should be in C:\Gestion AI2\web_nueva\templates\admin\includes_grappelli/ https://github.com/chronossc/django-grappelli/blob/master/grappelli/templates/admin/includes_grappelli/header.html – HydrUra Mar 09 '15 at 05:44
  • That's not in the latest version. – loar Mar 10 '15 at 08:17
  • True ! Sorry, I was looking on internet without checking that. So it's my install which is built like this. I am continuing the dev after someone ! – HydrUra Mar 10 '15 at 11:43
  • @Alex_Loar: well i add the same issue as you. The code sample from header.html is now in grappelli/templates/admin/base.html between line 90 and 100. But in my version, changes advised by HydrUra are already set. Check these and tell us what you find. https://github.com/sehmaschine/django-grappelli/blob/f01d693f273ca91d77c6b149251f9ee5ff652652/grappelli/templates/admin/base.html – jcs Apr 02 '15 at 12:19
  • @jcs Exactly, in my version those changes are already set so problems still there – loar Apr 10 '15 at 17:10
0

I've just gone through the same problem and here's a more step-by-step approach.

Create a directory in your project for the import_export templates and add a html file for the change_list_import template.

myproj
├── myproj
│   ├──url.py
│   ├──settings.py
├── manage.py
├── db_personal #myapp
│   ├── admin.py
│   ├── models.py
|   ├── viewss.py
├── templates
|   ├── admin
|   |   ├── import_export
|   |   |   ├── change_list_import.html 
├── dashboard.py

Next, copy the following code in this template html file. Note that it needs to extend the grappelli changelist template, hence the reference to the location of this template:

{% extends "C:/Python27/lib/site-packages/grappelli/templates/admin/change_list.html" %}
{% load i18n %}

{% block object-tools-items %}
   <li><a href="import/" class="import_link">{% trans "Import" %}</a></li>
   {{ block.super }}
{% endblock %}
brunostuyts
  • 654
  • 5
  • 10
  • Is there a way to avoid hardcoded path to the grappelli template? – Aleksei Petrenko Oct 11 '15 at 14:37
  • The answer [here](http://stackoverflow.com/questions/22784134/django-grappelli-change-form-html-override) provides a way using TEMPLATE_DIRS which controls the order in which templates are loaded – brunostuyts Oct 13 '15 at 11:01
0

grappelli needs to be before import_export within INSTALLED_APPS.

Quoting from https://django-grappelli.readthedocs.io/en/latest/thirdparty.html

4b0
  • 21,981
  • 30
  • 95
  • 142
Shrey
  • 569
  • 5
  • 14