-
-
Notifications
You must be signed in to change notification settings - Fork 7k
-
Suppose this is a scenario where I'm generating data for a chart by aggregating data with filters and searching in GenericAPIView.
class AnalyticsView(GenericAPIView): filterset_class = OrderFilter filter_backends = [DjangoFilterBackend, SearchFilter] queryset = Order.objects.select_related('delivery', 'platform') def get(self, request, *args, **kwargs): queryset = self.filter_queryset(self.get_queryset()) monthly_data = queryset.annotate( month=TruncMonth('date_of_sale') ).values('month').annotate( total_quantity=Sum('quantity_sold') ).order_by('month') data = [ { 'month': item['month'].strftime("%Y-%m"), value_field: item['total_quantity'] } for item in queryset ] return Response({'results': data })
So here Filter UI is not showing in the DRF template, because {'results': data }
and DRF have
def get_filter_form(self, data, view, request): if not hasattr(view, 'get_queryset') or not hasattr(view, 'filter_backends'): return # Infer if this is a list view or not. paginator = getattr(view, 'paginator', None) if isinstance(data, list): pass elif paginator is not None and data is not None: try: paginator.get_results(data) except (TypeError, KeyError): return elif not isinstance(data, list): return
this method returns None that's why UI filter UI not rendering.
I think it should not depend on the data instance.
It's my thought, let me know if I'm wrong in this.
Beta Was this translation helpful? Give feedback.
All reactions
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment