Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

list_display. How to display value from choices?

STATUS = (
    (1, "Sent"),
    (2, "Not send",),)

class Log(models.Model):
        status = models.CharField(max_length=255,choices=STATUS)

admin

class LogAdmin(admin.ModelAdmin):
    list_display=['status']

This display:

Status - (leer)

How to display Status - Sent or Not send here?

like image 541
user2307683 Avatar asked Apr 26 '13 11:04

user2307683


2 Answers

simply use:

class LogAdmin(admin.ModelAdmin):
    list_display=['get_status_display']

Django documentation: get_FOO_display

like image 96
Thomas Schwärzl Avatar answered Nov 02 '22 01:11

Thomas Schwärzl


(Updated to django 1.8) the best is to create a function

def get_status(self, obj):
    return obj.get_status_display()

get_status.short_description = 'Status'

Put 'get_status' in your list_display and Status it will be the column name in the admin list.

like image 10
Karim N Gorjux Avatar answered Nov 02 '22 03:11

Karim N Gorjux