django-unfold icon indicating copy to clipboard operation
django-unfold copied to clipboard

filter on Charfield with choices

Open summerthe opened this issue 1 year ago • 1 comments

I have a 'status' field as a CharField with three choices. I added it to the list_filter in the admin, but clicking on each link shows no results because the query parameter is being generated wrong.

# models.py
NEW = _("NEW")
PENDING = _("PENDING")
PAID = _("PAID")
STATUS_CHOICES = [
        (NEW, NEW.title()),
        (PENDING, PENDING.title()),
        (PAID, PAID.title()),
]

status = models.CharField(
        _("Status"),
        max_length=7,
        choices=STATUS_CHOICES,
    )
    
# admin.py
list_filter = (
        "status",
)

Query params when clicking on the Pending link from the filter.

/?status__exact=P&status__exact=E&status__exact=N&status__exact=D&status__exact=I&status__exact=N&status__exact=G

summerthe avatar Feb 08 '24 18:02 summerthe

This issue doesnt occur when used TextChoice class, instead of list of tuples for choices.

summerthe avatar Feb 20 '24 10:02 summerthe