Advertisement
hellsgate

paginated listapiview using django rest framework

Jun 25th, 2013
151
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.66 KB | None | 0 0
  1. class TagFilteredCustomerSerializer(serializers.ModelSerializer):
  2.     class Meta:
  3.         model = Customer
  4.  
  5.  
  6. class TagFilteredCustomerListView(ListAPIView):
  7.     '''
  8.    API endpoint which returns a list of customers filtered by tag
  9.    '''
  10.     serializer_class = TagFilteredCustomerSerializer
  11.     paginate_by = 10
  12.  
  13.     def get_queryset(self):
  14.         s = self.request.session
  15.         assert False
  16.         if 'tag_id' in self.request.GET.keys():
  17.             customer_list = get_customers_by_tag(self.request.GET['tag_id'])
  18.             if customer_list and customer_list.count() > 0:
  19.                 return customer_list
  20.  
  21.         return Customer.objects.all()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement