This is not a tuple?

I can’t understand what I am doing wrong here. My mistake: Incorrectly Configured in / admin / ' CategoryAdmin.fields ' should be a list or tuple.

Is CategoryAdmin.fields a tuple? Am I reading this wrong?

admin.py ..

class CategoryAdmin(admin.ModelAdmin): fields = ('title') list_display = ('id', 'title', 'creation_date') class PostAdmin(admin.ModelAdmin): fields = ('author', 'title', 'content') list_display = ('id', 'title', 'creation_date') admin.site.register( models.Category, CategoryAdmin ) admin.site.register( models.Post, PostAdmin ) 
+6
source share
4 answers

No, it is not. You need to add a comma:

 fields = ('title',) 

This is the comma that makes this tuple. The brackets here are simply optional:

 >>> ('title') 'title' >>> 'title', ('title',) 

Brackets, of course, are still a good idea, with root brackets it is easier to notice visually, and in brackets we distinguish a tuple in a function call from other parameters ( foo(('title',), 'bar') differs from foo('title', 'bar') ).

+14
source

It should be:

 fields = ('title', ) 

Example:

 In [64]: type(('title')) Out[64]: str In [65]: type(('title', )) Out[65]: tuple 
+4
source

Replace it as follows:

 fields = ('title', ) 
+3
source

You need a comma after the name:

 fields = ('title',) 
+3
source

All Articles