How to deserialize an object in Django Rest Framework?

Stuck with the question how to deserialize the object in the DRF.
Made a simple design (yet familiar) - to get the object, serialize it in JSON to deserialize to obtain the same object. Validation of the falls. Something tells me that there is a little thing which I did not consider.

the serializer
class UserSerializer(serializers.ModelSerializer): 
 class Meta:
 model = User
 fields = ('id', 'password', 'username', 'email', 'is_staff', 'is_superuser', 'is_active', 'date_joined')


what are trying to play
u = User.objects.get(id=request.user.id)
 u1 = UserSerializer(u).data
 uu1 = JSONRenderer().render(u1)
 uu2 = JSONParser().parse(io.BytesIO(uu1))
 u2 = UserSerializer(data=uu2)
 logger.debug(u2.is_valid()) # => False
 logger.debug(u2.errors) # => {'username': ['A user with that username already exists.']}
 logger.debug(u2.instance) # => null

I just get a User object back (the one that was in u) without case by checks for duplicates?
And even what it can be for duplicates, if the object is the same - id is present in the JSON.
June 10th 19 at 15:03
0 answer

Find more questions by tags Django