[Answered ]-Add label or modifying widget on django-filter form

1👍

you can do this by adding empty_label to your ModelChoiceFilters.

class PatientFilter(django_filters.FilterSet):

    ubication = django_filters.ModelChoiceFilter(
        queryset=Ubication.object.all(),
        empty_label="Placeholder",
    )

    class Meta:
        model = Patient
        fields = {
            'dni': ['exact'],
            'first_name': ['icontains'],
            'last_name': ['icontains'],
            'risk': ['exact'],
            'status': ['exact'],
            'ubication': ['exact'],
            'supervisor': ['exact'],
        }  

Edit:
For adding placeholder to CharFields you can try this:

from django.forms.widgets import TextInput  


class FooFilter(filters.FilterSet):
     bar = filters.CharFilter(..., widget=TextInput(attrs={'placeholder': 'baz'}))

Leave a comment