I have not created a filterset before but I use this code in my API views, 
and I am always able to filter in browsable API.

filter_backends = [DjangoFilterBackend]
filterset_fields = ['x', 'y', 'z']

And in settings.py:

REST_FRAMEWORK = {
...
    'DEFAULT_FILTER_BACKENDS': 
['django_filters.rest_framework.DjangoFilterBackend'],
...
}
On Wednesday, September 27, 2023 at 5:19:34 AM UTC-3 shekha...@gmail.com 
wrote:

> Hi,
>
> I am following these 
> https://github.com/encode/django-rest-framework/issues/4689, 
> https://stackoverflow.com/questions/63741389/django-rest-framework-filter-not-working-the-filter-button-is-not-showing-on-br
>  
> to see what I missed so that my filter not showing, sharing code snippet 
> which was used
>
> REST_FRAMEWORK = {
>     "DEFAULT_FILTER_BACKENDS": [
> "django_filters.rest_framework.DjangoFilterBackend"],
> }
>
>
> class ProductListAPIView(generics.ListAPIView):
>     serializer_class = ProductSerializer
>     filterset_class = ProductFilter
>
>     def get_queryset(self):
>         return ProductService().get_products()
>
>     def get(self, request, *args, **kwargs):
>         response = super().get(request, *args, **kwargs)
>         return send_response(
>             data=response.data,
>             status_code=response.status_code,
>             message=ResponseMessages.DATA_FETCH_SUCCESS,
>         )
>
> class ProductFilter(django_filters.FilterSet):
>     price_min = django_filters.NumberFilter(field_name="price", 
> lookup_expr="gte")
>     price_max = django_filters.NumberFilter(field_name="price", 
> lookup_expr="lte")
>
>     class Meta:
>         model = Product
>         fields = [
>             "brand",
>             "product_name",
>             "lens_category",
>             "price_min",
>             "price_max",
>         ]
>
> INSTALLED_APPS = [
>     "django.contrib.admin",
>     "django.contrib.auth",
>     "django.contrib.contenttypes",
>     "django.contrib.sessions",
>     "django.contrib.messages",
>     "django.contrib.staticfiles",
>     "django.contrib.postgres",
>     "rest_framework",
>     "products",
>     "crispy_forms",
>     "django_filters",
>     "drf_yasg",
> ]
>
> Django==4.2.4
> django-crispy-forms==2.0
> django-filter==23.2
> djangorestframework==3.14.0
>
> I tried to setup another basic new project with 1 model and in that case I 
> was able to see filter button 
> [image: Screenshot 2023-09-27 134800.png]
>
> but this didn't work on my main project, can anyone help me understand 
> what I missed on the above code snippet so that the filter not showing on 
> browsable API even tho it's showing on swagger with all options.
>
> I hope to get some help regarding this.
>
> Thanks
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django REST framework" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-rest-framework+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-rest-framework/1c3b8700-89fd-45fd-a615-2c7765653c76n%40googlegroups.com.

Reply via email to