不能将get_FOO_display与多级元组一起使用

时间:2015-12-17 21:03:01

标签: python django

我正在使用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')
    )
)

然后,当我尝试在admin中显示该字段时,我使用此:

# admin.py
list_display = ("title", 'get_repertory_category_display',)

但列名称显示为“curried”,值为数字。问题是,我必须有多个级别,以便客户可以轻松地轻松查看所有类别和子类别。

这是我使用的模型:

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)

有关如何进行的任何想法?感谢

1 个答案:

答案 0 :(得分:0)

尝试使用'repertory_category'中的list_display代替'get_repertory_category_display'

list_display = ("title", "repertory_category",)