M
M
Mike2018-10-26 21:35:11
Django
Mike, 2018-10-26 21:35:11

How to change a field in the model so that it belongs only to a specific user?

I have a progress field in the Level model.

class Level(models.Model):
    level = models.CharField(max_length=50, unique=True)
    helper = models.TextField(null=True, blank=True)
    progress = models.IntegerField(default=0)

It is necessary to add one by one to the progress field for each GET request. I need the progress field to store a different value for each user.
I don't know how to do it. At the moment I have a view that adds one at a time, but only globally.
class LevelProgress(APIView):

    def get(self, request, id):
        queryset_ = Level.objects.get(pk=id)
        queryset_.progress += 1
        queryset_.save()
        serializer = LevelFullSerializer(queryset_)
        return Response(serializer.data)

How can I bind the progress field to the user?

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question