Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork7k
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
-
Suppose this is a scenario where I'm generating data for a chart by aggregating data with filters and searching in GenericAPIView. classAnalyticsView(GenericAPIView):filterset_class=OrderFilterfilter_backends= [DjangoFilterBackend,SearchFilter]queryset=Order.objects.select_related('delivery','platform')defget(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'] }foriteminqueryset ]returnResponse({'results':data }) So here Filter UI is not showing in the DRF template, because and DRF have defget_filter_form(self,data,view,request):ifnothasattr(view,'get_queryset')ornothasattr(view,'filter_backends'):return# Infer if this is a list view or not.paginator=getattr(view,'paginator',None)ifisinstance(data,list):passelifpaginatorisnotNoneanddataisnotNone:try:paginator.get_results(data)except (TypeError,KeyError):returnelifnotisinstance(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. |
BetaWas this translation helpful?Give feedback.
All reactions
Replies: 0 comments
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment