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
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.
Thanks!
then there is a smal error in the docs:
http://www.djangoproject.com/documentation/tutorial02/
list_display = ('question', 'pub_date')
> 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>
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!