I have to pass the product_id (which is a string) into a view. There I have to do some DB operations based on the product id. How can I get that product id in that view? Actually what should be the parameter in the class ProductDetailConfiguration view? Now I am passing viewsets.ModelViewSet. Actually, this API call is not completely related to any model.
# urls.py
url(r'^product-configuration/(?P<product_id>[\w-]+)/$', views.ProductDetailConfiguration, name='product-configuration'),
# views.py
class ProductDetailConfiguration(viewsets.ModelViewSet):
queryset = Product.objects.all()
def get_queryset(self, **kwargs):
queryset = Product.objects.all()
product_id = self.request.get('product_id', None)
#filter query set based on the product_id
return queryset
serializer_class = ProductConfigurationSerializer