Reputation: 21
I am developing a project where I am using django_filters and there are some views where I have filters and apparently I have problems because of that. This is the message
UserWarning: <class 'apps.tenant_apps.orders.api.views.TotalProductsByOrderStateAPIView'> is not compatible with schema generation
and comes from django filters. I am following the documentation to the letter but I see no support for this warning. What should I do?
django_filters docs: https://django-filter.readthedocs.io/en/stable/index.html drf_yasg docs: https://drf-yasg.readthedocs.io/en/stable/
class ProductByCategoriesListView(TenantListApiViewMixin):
# 2. Listar productos por categoría o categorías
# http://example.localhost:8000/api/products/list/category/?categories=Electr%C3%B3nica,Ropa%20y%20Accesorios,Ropa,Calzado,Muebles%20y%20Decoraci%C3%B3n
serializer_class = ProductByCategorySerializer
def get_queryset(self):
categories = self.request.query_params.get('categories', '').split(',')
queryset = []
for category in categories:
# Utiliza Q objects para construir las condiciones OR
q_objects = Q()
q_objects |= Q(
channelproduct_product__productcategory_channelproduct__channel_category__category__icontains=category)
q_objects |= Q(
channelproduct_product__productcategory_channelproduct__integration_category__category__icontains=category)
# Filtra ProductModel con las condiciones OR
products = ProductModel.objects.filter(
q_objects).distinct().values_list('name', flat=True)
if products:
queryset.append({
'category': category,
'products': list(products)
})
return queryset
@swagger_auto_schema(tags=['Product'])
def list(self, request, *args, **kwargs):
queryset = self.get_queryset()
serializer = self.get_serializer(queryset, many=True)
return Response(serializer.data)
I expected this view to be placed in the Products tag but it sent me a warning.
Upvotes: 2
Views: 255