2010-11-24 103 views
0

我有一个模型对象说'类别'。我允许用户发布类别项目。类型模型有以下:Django如何通过管理状态list_display对象状态

models.py

LIVE_STATUS = 1 
DRAFT_STATUS = 2 
FOR_APPROVAL = 3 

STATUS_CHOICES = (
    (LIVE_STATUS, 'Live'), 
    (DRAFT_STATUS, 'Draft'), 
    (FOR_APPROVAL, 'For Approval'), 
) 


status = models.IntegerField(choices=STATUS_CHOICES, default=FOR_APPROVAL, 
    help_text=_("User posted reviews and categories are subject for approval. \ 
    Only entries with live status will be publicly displayed.")) 

现在即时通讯我admin.py

class CategoryAdmin(admin.ModelAdmin): 
    prepopulated_fields = { 'slug': ['name'] } 
    list_display = ('name','destinations', 'status', 'pub_date',) 
    ordering = ('status', 'pub_date',) 
    date_hierarchy = 'pub_date' 

我的问题是,我想单独显示在管理类别项目/或组通过状态。 例如: list_display活状态 list_display的审批状态 list_display现场草稿状态

任何提示?

回答

0

你可以在你的管理类中使用列表过滤器。添加

list_filter = ('status',) 

到您的CategoryAdmin类。这应该为您在条目列表右侧的侧栏上提供过滤器选项“全部”,“实时”,“草稿”和“批准”。点击其中一个将相应地过滤列表。另请参阅The Django Admin site并查找“list_filter”。

+0

多数民众赞成它!准确地工作。谢谢阿尔迪。 – 2010-11-25 10:17:26