Nursultan Ergeshov
Nursultan Ergeshov

Reputation: 61

How to change django-filter filtering key?

I've tried this way

class ProductFilter(django_filters.FilterSet):
    section = django_filters.ModelChoiceFilter(widget=CustomLinkWidget, queryset=Category.objects.filter(parent=None),
                                               label='Раздел', field_name='subcategory__parent__parent__slug')

Unfortunately filter keep doing this

http://localhost:8000/products/mediasabak-sub/mediasabak-sub-sub/?section=1

But i wanna something like this

http://localhost:8000/products/mediasabak-sub/mediasabak-sub-sub/?section=section_slug_here

Upvotes: 1

Views: 256

Answers (1)

Nursultan Ergeshov
Nursultan Ergeshov

Reputation: 61

fild_name = 'foreign_key_field_name__slug'
to_field_name = 'slug'

this two keyword arguments are important.

to_field_name doesn't work without field_name and field_name doesn't work without to_field_name

Upvotes: 1

Related Questions