开发者

Django how to list_display an object by status in admin

I have a model object say 'Category'. I allowed users to post Category item. The Category model has these:

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 pub开发者_StackOverflow中文版licly displayed."))

Now im my 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'

My problem is that I want to display Category items in admin separately/or by group via status. example: list_display for live status list_display for for approval status list_display for live drafts status

Any hints?


Try using the admin filters. Here is how: Django Admin - List Filter


You could use list filters in your admin class. Add

list_filter = ('status',)

to your CategoryAdmin class. This should offer you the filter options 'All', 'Live', 'Draft' and 'For Approval' on a side bar right to the list of entries. Clicking one of them will filter the list accordingly. See also The Django Admin site and look for 'list_filter'.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜