python - django-rest-framework non orm-based filtering -


i using djangorestapi , while works charm queryset (orm-based) views, struggling make views use different back-end behave same way orm-based views are. notably want add filters , have them cast , validated automatically.

pseudo code below:

class newsfilter(django_filters.filterset):     category = django_filters.numberfilter(name='category')     limit = django_filters.numberfilter(name='limit')     page = django_filters.numberfilter(name='page')   class newsview(generics.apiview):     filter_class = newsfilter      def get(self, request):         filters = self.filter_class(??)  # not sure, put here          payload = logic.get_business_news(**filters.data)  # same          return response(payload, status=status.http_200_ok) 

any hint how tackle problem appreciated.

ultimate goal to:

  • user types url or sends via post, django-rest intercepts relevant values, extracts them, casts them correct type , return dictionary
  • filters displayed if serializer orm based

the function signature single filter like

class myfilter(django_filters.filter):     def filter(self,queryset,value):         [...] 

the function signature filterset is:

def __init__(self, data=none, queryset=none, prefix=none, strict=none): 

so, looks pass in request.get data param , pass in queryset.


Comments

Popular posts from this blog

account - Script error login visual studio DefaultLogin_PCore.js -

xcode - CocoaPod Storyboard error: -