list_display must be list or tuple

2,229 views
Skip to first unread message

niels

unread,
Jul 23, 2008, 5:21:29 PM7/23/08
to Django users
I am setting up de admin pages (SVN version).
I get this error:

django.core.exceptions.ImproperlyConfigured: `PageAdmin.list_display`
must be a list or tuple.


models.py:

class Page(models.Model):
status = models.ForeignKey(Status)
name = models.CharField(max_length=200)

class PageAdmin(admin.ModelAdmin):
fields = ['name', 'status']
search_fields = ['name']
list_display = ('name')


admin.site.register(Page,PageAdmin)


Someone a suggestion?

Niels

Matthias Kestenholz

unread,
Jul 23, 2008, 5:23:08 PM7/23/08
to django...@googlegroups.com
2008/7/23 niels <niels....@gmail.com>:

Yes, you forgot a comma:

list_display = ('name',)

or use

list_display = ['name']

It's only marginally slower if at all and you don't have to think of the
comma for a single-argument tuple/list.

Niels

unread,
Jul 23, 2008, 5:43:45 PM7/23/08
to Django users
Thanks!

then there is a smal error in the docs:

http://www.djangoproject.com/documentation/tutorial02/

list_display = ('question', 'pub_date')


On Jul 23, 11:23 pm, "Matthias Kestenholz" <m...@spinlock.ch> wrote:
> 2008/7/23 niels <niels.siem...@gmail.com>:

Karen Tracey

unread,
Jul 23, 2008, 5:50:06 PM7/23/08
to django...@googlegroups.com
On Wed, Jul 23, 2008 at 5:43 PM, Niels <niels....@gmail.com> wrote:

Thanks!

then there is a smal error in the docs:

http://www.djangoproject.com/documentation/tutorial02/

list_display = ('question', 'pub_date')


What's the error in the docs?  That example doesn't need a trailing comma because the tuple has more than one element. 

Karen
 

Fredrik Lundh

unread,
Jul 23, 2008, 5:59:22 PM7/23/08
to django...@googlegroups.com
Matthias Kestenholz wrote:

> Yes, you forgot a comma:
>
> list_display = ('name',)
>
> or use
>
> list_display = ['name']
>
> It's only marginally slower if at all and you don't have to think of the
> comma for a single-argument tuple/list.

Lists need two allocations from object space instead of one, so there's
a tiny theoretical difference, but that's hardly anything that you have
to be concerned about unless you're sticking the code inside a tight,
performance-critical inner loop.

</F>

Rishabh Manocha

unread,
Jul 24, 2008, 2:07:49 AM7/24/08
to django...@googlegroups.com
Neils,

The docs are correct - in Python, single-item tuples need to have a trailing comma. So

list_display = ('name') is wrong, whereas

list_display = ('name', ) is correct (see [1]).

Best,

R

[1] - http://docs.python.org/tut/node7.html#SECTION007300000000000000000

Norman Harman

unread,
Jul 24, 2008, 11:53:53 AM7/24/08
to django...@googlegroups.com
Rishabh Manocha wrote:
> Neils,
>
> The docs are correct - in Python, single-item tuples need to have a
> trailing comma. So
>
> list_display = ('name') is wrong, whereas
>
> list_display = ('name', ) is correct (see [1]).

A good (and correct) way to remember/think about this is to know that
the tuple "operator" is the comma. Parens are just a (sometimes
required) grouping mechanism

These are identical tuples:
(this, is, a, tuple)
this, is, a, tuple

Likewise:
(atuple,)
atuple,

On the other hand
(bareword)
bareword

So, think you have a tuple? Mentally remove the parens, still look like
tuple, good. If not, then you ain't got a tuple.


The main places I see parenless tuples are assignments to tuples aka
multiple assignment and function params

(one, two) = split("one two)
one, two = split("one two)

myfunc(params, are, a, tuple, followed="by", a="dictonary", sort="of")

Realizing that helped me understand *args and **kwargs better.

--
Norman J. Harman Jr.
Senior Web Specialist, Austin American-Statesman
___________________________________________________________________________
You've got fun! Check out Austin360.com for all the entertainment
info you need to live it up in the big city!

Reply all
Reply to author
Forward
0 new messages