First, please see the Issue #1440 .
This is about Issue #1440 "2. published_on" field is present in "Book model".
I think it would be better to change it as following.
class Meta:
model = Book
# fields = ['published']
fields = ['published_on']
Modified code was tested with following change on the test section of #1440.
# models.py
from django.db import models
...
class Book(models.Model):
name = models.CharField(max_length=255)
# published = models.DateTimeField(null=True)
published_on = models.DateTimeField(null=True)
# views.py
from django_filters import BooleanFilter
...
class F(filters.FilterSet):
published = BooleanFilter(field_name="published_on", method="filter_published")
def filter_published(self, queryset, name, avlue):
lookup = "__".join([name, "isnull"])
print(lookup)
return queryset.filter(**{lookup: False})
class Meta:
model = Book
fields = ["published_on"]
# fields = ["published"]
Creating test database for alias 'default'...
System check identified no issues (0 silenced).
published_on__isnull
.
----------------------------------------------------------------------
Ran 1 test in 0.469s
OK
Destroying test database for alias 'default'...
First, please see the Issue #1440 . This is about Issue #1440 "2. published_on" field is present in "Book model". I think it would be better to change it as following.
Modified code was tested with following change on the test section of #1440.
The result was successful.