Specifying a FilterSet for Django-rest-framework -


the tutorial said:

class productfilter(django_filters.filterset):     min_price = django_filters.numberfilter(lookup_type='gte')     max_price = django_filters.numberfilter(lookup_type='lte')     class meta:         model = product         fields = ['category', 'in_stock', 'min_price', 'max_price'] 

but when try this, error:

fielderror: cannot resolve keyword u'min_price' field. choices are: cantidad, datetime, enlace, id, id_fila, nivel

min_price not in models, need create new parameter. (it example) need filter dates.

see django-filter documentation.

since min_price , max_price filters don't have same name model field refer too, need provide name argument.

class productfilter(django_filters.filterset):     min_price = django_filters.numberfilter(name='price', lookup_type='gte')     max_price = django_filters.numberfilter(name='price', lookup_type='lte')     class meta:         model = product         fields = ['category', 'in_stock', 'min_price', 'max_price'] 

Comments

Popular posts from this blog

Why does Ruby on Rails generate add a blank line to the end of a file? -

keyboard - Smiles and long press feature in Android -

node.js - Bad Request - node js ajax post -