I want to make an api to get the detail view of a blog from a list of published blog posts. To solve that, I am using get_queryset() filters to solve this, but it is simply giving back all the list, i.e. no filter worked.
I have used the code as shown below:
models.py
class BlogModel (models.Model) :
heading = models.CharField(max_length=254)
blog = models.TextField()
author = models.CharField(max_length=254)
views.py
class BlogRetrieveView(generics.RetrieveUpdateDeleteAPIView):
serializer_class=BlogListSerializer
queryset=BlogModel.objects.all()
lookup_field='blog_id'
def get_queryset(self,*args, **kwargs):
return BlogModel.objects.filter(
blog__id=self.kwargs['blog_id']
serializers.py
class BlogListSerializer(serializers.ModelSerializer):
class Meta:
model = BlogModel
fields = '__all__'
urls.py
url(r'^blog/(?P<blog_id>\d+)/$',BlogRetrieveView.as_view()),
I am getting the following output:
This shows 1 out of 7 blog post shown in a list. Clearly, the filter wasn't applied.
Edit 1: With the given advices, my code on localhost worked, but the production website is still stuck on a situation mentioned in the problem above. What can be the reason behind it?