user1255933
user1255933

Reputation: 202

django admin list_filter does not display (None) for choice field

My model contains a choice field that is nullable:

status = models.CharField(max_length=255, choices=STATUS_CHOICES, blank=True, null=True)

The filter in my ModelAdmin:

list_filter = ['status']

does not display (None) as an option, even though the table for the model contains NULL values for that field.

What am I doing wrong?

Upvotes: 4

Views: 3110

Answers (1)

AndrewS
AndrewS

Reputation: 1676

This post might be of use: Filtering Django Admin by Null/Is Not Null

When using choices I'd recommend setting a default value which is in the choices list or tuple. This ensures the get_FOO_display method works for all values too.

https://docs.djangoproject.com/en/dev/ref/models/fields/#choices

Upvotes: 2

Related Questions