Answer the question
In order to leave comments, you need to log in
How to get the fields of the current user?
I have a model.
class UserLevel(models.Model):
level = models.ForeignKey(Level, on_delete=models.CASCADE)
user = models.ForeignKey(User, on_delete=models.CASCADE)
progress = models.IntegerField(default=0)
class UserProgressList(APIView):
def get(self, request, format=None):
queryset_ = UserLevel.objects.filter(user_id=request.user.id)
# queryset_ = UserLevel.objects.filter(user_id=request.user.id).values_list('progress', flat=True)
serializer = UserLevelSerializer(queryset_)
return Response(serializer.data)
Original exception text was: 'QuerySet' object has no attribute 'level'.
Answer the question
In order to leave comments, you need to log in
serializer = UserLevelSerializer(queryset_, many=True)
filter
returns not a model object, but QuerySet
objects. Useget
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question