0

The filter options on django admin for a date are:

Any date Today Past 7 days This month This year

What is the easiest way to add "None" that filters on blank dates?

PhoebeB
  • 8,434
  • 8
  • 57
  • 76

3 Answers3

1

I just wrote a custom filter for this purpose. It extends Django admin's default DateTimeListFilter and adds "None" and "Not None" options, which do what you think they do.

https://djangosnippets.org/snippets/10566/

You can then go on to use it:

class MyAdmin(ModelAdmin):
    list_filter = (('my_date_field', DateFieldListFilterOrNull),
                  )
Amichai Schreiber
  • 1,528
  • 16
  • 16
0

Think you're looking for the __isnull postfix. For example:

>>> mymodels = MyModel.objects.filter(mydate__isnull=True)
>>> mymodels[0].mydate
(no response)
>>>
Chris Pratt
  • 232,153
  • 36
  • 385
  • 444
0

You'll have to register your own filter - look at Custom Filter in Django Admin on Django 1.3 or below or http://twigstechtips.blogspot.com/2010/10/django-create-custom-admin-model-filter.html or lots of other places for how that's done.

Regarding your particular requirement, a snippet for an "IS NULL/IS NOT NULL" filter at http://djangosnippets.org/snippets/1963/

Community
  • 1
  • 1
Danny W. Adair
  • 12,498
  • 4
  • 43
  • 49