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/f11d5d7e-4031-4bc6-8411-5117af49aec4n%40googlegroups.com.

Reply via email to