[英]Can't use get_FOO_display with multiple level tuple
I'm using Django 1.6 and I have to make a choice field (for which I use models.IntegerField) with choices that look like this: 我使用的是Django 1.6,我必须选择一个字段(我使用models.IntegerField),其选择如下所示:
# models.py
REPERTORY_CATEGORIES = (
('Whatever', (
(1, 'Whatever'),
(2, 'Whatever'),
(3, 'Whatever'),
(4, 'Whatever')
)
), ('Whatever', (
(5, 'Whatever'),
(6, 'Whatever'),
(8, 'Whatever'),
(9, 'Whatever'),
(10, 'Whatever'),
(11, 'Whatever')
)
)
Then when I try to show the field in admin, I use this: 然后,当我尝试在admin中显示该字段时,将使用以下命令:
# admin.py
list_display = ("title", 'get_repertory_category_display',)
But the column name shows as "curried" and the value is the number. 但是列名显示为“ curried”,值是数字。 Problem is, I must have multiple levels so the client can easily see all his categories and subcategories easily.
问题是,我必须具有多个级别,以便客户可以轻松查看其所有类别和子类别。
Here's the models I use: 这是我使用的模型:
class BaseLinks(Displayable):
website = models.CharField(verbose_name="URL du lien", max_length=200, null=True, blank=True)
search_fields = ['title']
def __unicode__(self):
return self.title
class Meta:
ordering = ['title']
class RepertoryLinks(BaseLinks):
# List of categories
REPERTORY_CATEGORIES = (
('Whatever', (
(1, 'Whatever'),
(2, 'Whatever'),
(3, 'Whatever'),
(4, 'Whatever')
)
), ('Whatever', (
(5, 'Whatever'),
(6, 'Whatever'),
(8, 'Whatever'),
(9, 'Whatever'),
(10, 'Whatever'),
(11, 'Whatever')
)
)
excerpt = RichTextField(verbose_name="Bref résumé des services offerts ou de la mission de l'organisation",
null=True, blank=True)
address = models.CharField(verbose_name="Adresse", max_length=200, null=True, blank=True)
city = models.CharField(verbose_name="Ville", max_length=200, null=True, blank=True)
zipcode = models.CharField(verbose_name="Code Postal", max_length=200, null=True, blank=True)
telephone = models.CharField(verbose_name="Téléphone", max_length=200, null=True, blank=True)
fax = models.CharField(verbose_name="Télécopieur", max_length=200, null=True, blank=True)
contactname = models.CharField(verbose_name="Personne ressource", max_length=200, null=True, blank=True)
email = models.EmailField(verbose_name="Courriel", max_length=254, null=True, blank=True)
ik_image = FileField("Image", max_length=200, upload_to="", blank=True, null=True)
repertory_category = models.IntegerField(verbose_name="Catégorie de Répertoire", max_length=255, choices=REPERTORY_CATEGORIES)
Any ideas on how to proceed? 关于如何进行的任何想法? Thanks
谢谢
尝试在list_display
使用'repertory_category'
,而不是'get_repertory_category_display'
。
list_display = ("title", "repertory_category",)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.