Question

I am trying to get a value from request and really suprised an error is being raised.

def product_view(request):
    lookup_type_user = request.GET.get('lookup_type', '')

    LOOKUP_TYPE_CHOICES = (
                ('gt', '>'),
                ('lt', '<'),    
              )

    class ProductFilter(django_filters.FilterSet):
        lookup_type = django_filters.ChoiceFilter(choices=LOOKUP_TYPE_CHOICES)
        price = django_filters.NumberFilter(lookup_type=lookup_type_user)

This line, being basically the same, works fine.

price = django_filters.NumberFilter(lookup_type='gte')

I am not posting the error message because it's a package relevant one and since the line above where I provided lookup_type by hand did not raise anything I am assumming it has nothing to do with that package but the code above.

Can you see what goes wrong here?

@EDIT

Is there a way I can print out the request to see what it contains exactly?

Was it helpful?

Solution

I got it working. It was my ignorance. I had to redefine lookup_type in forms.py instead. Like this:

lookup_type = forms.ChoiceField(choices=LOOKUP_TYPE_CHOICES)

and not:

lookup_type = django_filters.ChoiceFilter(choices=LOOKUP_TYPE_CHOICES)

Because what django-filter was doing, it was trying to filter the lookup_type field, which does not exist in my models. It was throwing an error FieldError at/. Cannot resolve keyword 'lookup_type' into field, which I did not know about because another app I am using - django_tables2 modified this error to something else, which tricked me successfully.

It's probably a useless thread now but I just want to let pleople who tried to solve this, know.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top