Take the 2-minute tour ×

From the Django intro tutorial, in \mysite\polls\admin.py:

from django.contrib import admin
class PollAdmin(admin.ModelAdmin):
  inlines = [ChoiceInline]
  list_filter = ['pub_date']

admin.site.register(Poll, PollAdmin)

Why do inlines and list_filter both use lists, while list_display uses a tuple? Do inlines and list_filters need to be mutable for some reason?

I'm just trying to understand the design decision here.

share|improve this question
Really, I'm looking for a logical way to remember whether the property is a list or a tuple. –  Mike M. Lin Sep 8 '10 at 20:06
add comment

1 Answer

up vote 4 down vote accepted

It doesn't matter which you use because Django (and you) will never change them during runtime. All that's important is that the value be an iterable of strings. I often use foo = ["something"] when there is only one element because I've gotten nailed so often when I accidentally say foo = ("somthing") instead of foo = ("something",).

I would put this one-element-tuple-notation issue on my list of Python irritants, right after "significant whitespace". That said, I still love the language.

share|improve this answer
Verified. Either a list or a tuple will do here -- it worked both ways. And if you try some other data type, you'll get an error similar to this: 'PollAdmin.list_filter' must be a list or tuple. –  Mike M. Lin Sep 9 '10 at 16:04
add comment

Your Answer


