Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

filter on Charfield with choices #284

Open
summerthe opened this issue Feb 8, 2024 · 1 comment
Open

filter on Charfield with choices #284

summerthe opened this issue Feb 8, 2024 · 1 comment

Comments

@summerthe
Copy link

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
Copy link
Author

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant