S
S
Sergey Y2021-10-27 10:51:12
Django
Sergey Y, 2021-10-27 10:51:12

How to get "display" value in Django-filter?

The model has a CharField using choices defined:

CHANGE = (
        ('1', '1 смена'),
        ('2', '2 смена'),
        ('3', '3 смена'),
    )
 change = models.CharField(verbose_name='Смена', max_length=20, choices=CHANGE)

If we apply the simplest construction in django-filter:
class StateFilter(django_filters.FilterSet):
    class Meta:
        model = State
        fields = ['change']

THEN everything is displayed as it should, but in the form of an automatically defined ChoiceFilter and display values ​​in the dropbox, but I need checkboxes and when defining a filter in a different way, I can’t get them in any way, only 1,2,3 are displayed
change = django_filters.AllValuesMultipleFilter(
        field_name = 'change',
        widget = forms.CheckboxSelectMultiple,
   )

How can I display the values ​​"1 shift" here???

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question