Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

filter form not rendering on UI of drf if changes value in Response class.#9653

Unanswered
sainipray asked this question inGeneral
Discussion options

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{'results': data }

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.

You must be logged in to vote

Replies: 0 comments

Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Category
General
Labels
None yet
1 participant
@sainipray

[8]ページ先頭

©2009-2025 Movatter.jp