Skip to content

PetrDlouhy/django-isnull-list-filter

Repository files navigation

Django isNull list_filter

image

image

image

Simple list_filter that offers filtering by __isnull or by blank char field.

Read before using this app

Starting with Django 3.1 the EmptyFieldListFilter class was embedded: https://docs.djangoproject.com/en/4.1/ref/contrib/admin/filters/#using-a-field-name-and-an-explicit-fieldlistfilter

It has very similar purpose as this app, although it might be little bit less configurable. Consider using plain Django before using this app.

Documentation

The full documentation is at https://django-isnull-list-filter.readthedocs.io.

Quickstart

Install django-isnull-list-filter:

pip install django-isnull-list-filter

or use development version:

pip install -e git+https://github.com/PetrDlouhy/django-isnull-list-filter#egg=django-isnull-list-filter

Directly use it in your admin:

from isnull_filter import isnull_filter
  class MyAdmin(admin.ModelAdmin):
     list_filter = (
         isnull_filter('author'),  # Just set the field
         isnull_filter('author', _("Hasn't got author")),  # Or you can override the default filter title
         isnull_filter('author', _("Has got author"), negate=True),  # And you can negate the condition
     )

or:

from isnull_filter import isblank_filter
  class MyAdmin(admin.ModelAdmin):
     list_filter = (
         isblank_filter('author'),  # Just set the field
         isblank_filter('author', _("Hasn't got author")),  # Or you can override the default filter title
         isblank_filter('author', _("Has got author"), negate=True),  # And you can negate the condition
     )

Features

  • Can be used on:
    • simple field
    • ForeignKeyField
    • related ForeignKeyField
    • ManyToManyField
    • OneToOneField
  • Default title can be overriden

Running Tests

Does the code actually work?

source <YOURVIRTUALENV>/bin/activate
(myenv) $ pip install tox
(myenv) $ tox

Credits

Author:

  • Petr Dlouhý

Tools used in rendering this package:

About

Simple list_filter that offers filtering by __isnull.

Resources

License

Stars

Watchers

Forks

Packages

No packages published