I have a class extend with GenericAPIView ,
I Can access to the lookup_field in my functions, but I can't use it in the queryset function.
class SellerItemAPIView(GenericAPIView, ListModelMixin):
serializer_class = ShopItemSerializer
permission_classes = [AllowAny]
lookup_field = 'phone_number'
def get_queryset(self):
print(self.lookup_url_kwarg) # It Return None
print(self.lookup_field) # It Return 'phone_number'
shop_items = ShopItem.objects.filter(Q(seller_id__user_id__phone_number=self.lookup_field))
return shop_items
def get(self, request, phone_number):
result = self.list(request, phone_number)
print(result.status_code)
return result
How Can I Access to the lookup_field in get_queryset ?
I found the answer:
Remove this line from class:
lookup_field = 'phone_number'
Get the lookup_field
in get_queryset
, like this:
phone_number = self.kwargs.get('phone_number')