Unable to load a modified tabular.html

30 views
Skip to first unread message

Vittorio

unread,
Oct 24, 2013, 11:32:43 AM10/24/13
to django...@googlegroups.com
Context: Mac OS X 10.7, Django 1.5.4 using Admin

I was able to taylor the admin/edit_inline/tabular.html to eliminate some redundant info (such as the obsessive label indicating from which Object is extracted the inline record, repeated record by record!) in my many inlines putting the revised tabular.html under $MYPROJECT/templates/admin/edit_inline/. It works like a charm!

Now, for a specific model only I need to modify tabular.html eliminating the 'delete?' label and the relating little boxes in each record of the inline model.
Therefore I created a mytabular.html file and put it under myproject/templates/admin/ then in

# views.py
def mytabular(request):
return render_to_response('mytabular.html')

# urls.py
urlpatterns = patterns('',
.............
url(r'^magazzino/', include(admin.site.urls)),
url(r'^movimentoordine/(\d+)/$', 'magazzino.views.mytabular', name='mytabular'),
)

[The called url is e.g. 'http://localhost:8000/magazzino/magazzino/movimentoordine/2/']

Unfortunately django doesn't seem to take my desire into account and invariably calls admin/edit_inline/tabular.html instead of mytabular.html as debug_toolbar says.
I tried also to put mytabular.html under $MYPROJECT/templates/admin/edit_inline/ to no avail.

Please help.
Ciao
Vittorio

micha...@gmail.com

unread,
Oct 24, 2013, 12:11:41 PM10/24/13
to django...@googlegroups.com, ml-...@de-martino.it
You may try this:

1. Create new folders under $MYPROJECT named my_templates/admin/edit_inline/

2. Save your customized tabular.html under my_templates/admin/edit_inline/

3. Edit settings.py as below:
TEMPLATE_DIRS = (
    # Put strings here, like "/home/html/django_templates" or "C:/www/django/templates".
    # Always use forward slashes, even on Windows.
    # Don't forget to use absolute paths, not relative paths.
    os.path.join(os.path.dirname(__file__), 'my_templates'),
    os.path.join(os.path.dirname(__file__), 'templates'),
)


Then django will try to find the templates from my_templates first, than the standard one.




Michael
在 2013年10月24日星期四UTC+8下午11时32分43秒,Vittorio写道:

Pantelis Petridis

unread,
Oct 24, 2013, 1:00:54 PM10/24/13
to django...@googlegroups.com
You don't have to create any custom view. Just set the template in your inline model

class MyInline(admin.TabularInline):
      template = 'path/to/the/template.html'

Hope this helps!
--
Pantelis Petridis
e-mail: ppe...@yawd.eu
url: Yawd web applications
ppetridis.vcf

Vittorio

unread,
Oct 24, 2013, 2:28:08 PM10/24/13
to django...@googlegroups.com
It helped indeed. Thank you very much!
Vittorio
Reply all
Reply to author
Forward
0 new messages