mrts / django-admin-list-filter-dropdown

Use dropdowns in Django admin list filter
MIT License
315 stars 48 forks source link

Not working with choices field #15

Closed luizrrodrigues closed 5 years ago

luizrrodrigues commented 5 years ago

Looks like not working with field that have choice, like:

class Plan(models.Model):
    STATUS_WAITING = 0
    STATUS_ACTIVE = 1
    STATUS_EXPIRED = 2
    STATUS_CANCELED = 3
    STATUS = (
        (STATUS_WAITING , u'Waiting'),
        (STATUS_ACTIVE , u'Active'),
        (STATUS_EXPIRED, u'Expired'),
        (STATUS_CANCELED , u'Canceled'),
    )

    status = models.IntegerField(
        choices=STATUS, default=STATUS_WAITING)

When try use this in first time, if list data not have all status option present, this will return normal field (without dropdown) and with values 0, 1, 2, etc.

So add all possible status to data, now dropdown is rendered but values is 0, 1, 2, etc..

mrts commented 5 years ago

You have to use ChoiceDropdownFilter. Can you please submit a pull request for documenting this in README.md?

luizrrodrigues commented 5 years ago

MR sent.

dwasyl commented 5 years ago

Not to dredge up an old issue, but having just started with this package, when I use ChoiceDropdownFilter it doesn't seem to do anything. The options are just rendered as a regular list. When I use the standard DropdownFilter the actual values are rendered (but still as the standard admin list).

Nevermind, I can into the minimum list length issue (only had 3 choices). Will just override the template to adjust for this.

Also the docs aren't totally clear if this filter is needed for just ChoiceField choice fields or also CharFields with choices= set.

mrts commented 5 years ago

@dwasyl, Can you please submit a pull request to clarify these points?