4

I made a simple Django app. I have one model "Visitor". My goal is to have two tables appear in the Django admin. One with all of the visitors and one with only those for today.

I got everything working with the code below by following these instructions. But I'm not sure how to override just the change_list.html for just VisitorExpectedTodayProxy.

I tried following the instructions here and I created Site/templates/admin/VisitorLog/VisitorExpectedTodayProxy/change_list.html and made my changes there, but it doesn't seem to be picking it up.

Models.py

class Visitor(models.Model):
    visit_datetime = models.DateTimeField(null=True)
    visitor_name = models.CharField(max_length=500)

#Make dummy models for different object views in admin interface
class VisitorExpectedTodayProxy(Visitor):
    class Meta:
        proxy=True
        verbose_name = "Visitor"
        verbose_name_plural = "Today's Visitors and Regular Visitors"
Taylan Aydinli
  • 4,333
  • 15
  • 39
  • 33
Greg
  • 45,306
  • 89
  • 231
  • 297

2 Answers2

7

On top of lowercasing your paths to look like:

templates/admin/visitorlog/visitorexpectedtodayproxy/change_list.html

The content of your change_list.html should extend the default admin/change_list:

{% extends "admin/change_list.html" %}

You can customise the different section of this page by looking at the various block templates in the django source code:

django/contrib/admin/templates/admin/change_list.html
Thierry Lam
  • 45,304
  • 42
  • 117
  • 144
  • I just copied change_list.html into the directory and modified it there. Is there a better way? – Greg Mar 30 '11 at 17:10
5

Try lowercasing your folder names.

Note, that the admin app will lowercase the model name when looking for the directory, so make sure you name the directory in all lowercase if you are going to run your app on a case-sensitive filesystem.

Also, have you gone through the checklist of making sure your templates directory is working at all? TEMPLATE_DIRS needs to contain this templates folder of yours, and make sure the filesystem template loader comes before the app_directories loader.

Finally, you can point to a template via a ModelAdmin attribute: http://docs.djangoproject.com/en/dev/ref/contrib/admin/#django.contrib.admin.ModelAdmin.change_list_template

Yuji 'Tomita' Tomita
  • 115,817
  • 29
  • 282
  • 245