Issue
this is my views.py
@api_view(['GET'])
def home(request):
if request.method == 'GET':
movies=Watchlist.objects.all()
serializer=WatchlistSerializer(Watchlist,many=True)
return Response(serializer.data)
this is serializers.py
class WatchlistSerializer(serializers.ModelSerializer):
class Meta:
model=Watchlist
fields="__all__"
this is models.py
class Watchlist(models.Model):
title=models.CharField(max_length=50)
storyline=models.CharField(max_length=200)
activate=models.BooleanField(default=True)
create=models.DateTimeField(auto_now_add=True)
def __str__(self):
return self.title
it is showing error model class not iterable.
Solution
observe the lines below
movies=Watchlist.objects.all()
serializer=WatchlistSerializer(Watchlist,many=True)
the QuerySet is captured in movies
not in Watchlist
it should be like this serializer=WatchlistSerializer(movies,many=True)
Answered By - jack
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.