title: Serializer for creation of user profile in Django Rest Framework
body: <p>I am trying to update the user profile in django rest framework
  So i am able to create the user profile simultaneously with user creation using signals</p>
  <p>Now i am trying to update the profile created:-</p>
  <p>//models.py</p>
  <pre><code>class User(AbstractBaseUser,PermissionsMixin):
      phone_regex=RegexValidator(regex = r'^[6-9]\d{9}$',message='please enter the correct phonenumber')
  
      #name_regex=RegexValidator(regex=r'/^[A-Za-z]+$/',message='Please enter the correct name')
      
      phone=models.CharField(validators=[phone_regex],max_length=15,unique=True)
      
      date_joined=models.DateTimeField(verbose_name='date joined',auto_now_add=True)
      last_login=models.DateTimeField(verbose_name='last login',auto_now=True)
      active = models.BooleanField(default=True)
      staff = models.BooleanField(default=False) # a admin user; non super-user
      admin = models.BooleanField(default=False)
      first_login=models.BooleanField(default=True)
  
      USERNAME_FIELD='phone'
      REQUIRED_FIELDS = [] 
  
  class UserProfile(models.Model):
      # There is an inherent relationship between the Profile and
      # User models. By creating a one-to-one relationship between the two, we
      # are formalizing this relationship. Every user will have one -- and only
      # one -- related Profile model.
  
      GENDER = (
          ('M', 'Homme'),
          ('F', 'Femme'),
      )
      user = models.OneToOneField(
          User,related_name=&quot;profile&quot;, on_delete=models.CASCADE
      )
  
      # Each user profile will have a field where they can tell other users
      # something about themselves. This field will be empty when the user
      # creates their account, so we specify blank=True.
      email=models.EmailField(unique=True,validators=[validate_email],max_length=254,blank=True,null=True)
      name=models.CharField(max_length=15,blank=True)
      dateofbirth=models.DateField(auto_now=False, null=True, blank=True)
      Gender=models.CharField(max_length=1, choices=GENDER,blank=True,null=True)
      address1 = models.CharField(
          &quot;Address&quot;,
          max_length=1024,
          blank=True,
          null=True
      )
  
      address2 = models.CharField(
          &quot;Society&quot;,
          max_length=1024,
          blank=True,
          null=True
  
      )
      address3 = models.CharField(
          &quot;Landmark&quot;,
          max_length=1024,
          blank=True,
          null=True
          
      )
      zip_code = models.CharField(
          &quot;ZIP / Postal code&quot;,
          max_length=12,
          blank=True,
          null=True
      )
  
      city = models.CharField(
          &quot;City&quot;,
          max_length=1024,
          default =&quot;Gurugram&quot;,
          blank=True,
          null=True
      )
  
      country = models.CharField(
          &quot;Country&quot;,
          max_length=10,
          default=&quot;India&quot;,
          blank=True,
          null=True
      )
  
      # In addition to the `bio` field, each user may have a profile image or
      # avatar. This field is not required and it may be blank.
  
      # A timestamp representing when this object was created.
      created_at = models.DateTimeField(auto_now_add=True,blank=True)
  
      # A timestamp representing when this object was last updated.
      updated_at = models.DateTimeField(auto_now=True,blank=True)
  
      def __str__(self):
          return self.user.phone
  
  @receiver(post_save, sender=User)
  def create_profile_for_user(sender, instance=None, created=False, **kargs):
          if created:
              UserProfile.objects.get_or_create(user=instance)
  </code></pre>
  <p>// Serializer.py</p>
  <pre><code>class UserProfileSerializer(serializers.ModelSerializer):
      class Meta:
          model = UserProfile
          fields=(&quot;name&quot;,)
  
  class UserSerializer(serializers.ModelSerializer):
      user = UserProfileSerializer(many=True)
      class Meta:
          model = User
          fields = ('user', 'phone',)
  
      def create(self, validated_data):
          user_data = validated_data.pop('user')
          user = User.objects.create(**user_data)
          profile = user_data.objects.create(user=user, **validated_data)
          return profile 
      
      def update(self, instance, validated_data):
              
              print(&quot;update function&quot;)
          
          #    profile_data = validated_data.pop('profile')
          #    print(profile_data)
              profile_data = validated_data.pop('user')
              profile = instance.profile
            #  print(&quot;profile is &quot;,profile)
  
              print(profile_data.name)
              print(&quot;name in validation &quot;,validated_data['name'], &quot; type is &quot;,print(type(validated_data)))
  
              instance.username = validated_data.get('name', instance.username)
              instance.email = validated_data.get('email', instance.email)
              instance.save()
              print(&quot;name is &quot;,instance.profile.name )
              #profile.Gender = validated_data['Gender'],
              #profile.email = validated_data['email'],
              #profile.dateofbirth=validated_data['dateofbirth'],
              #profile.address1=validated_data['address1'],
              ##profile.address2=validated_data['address2'],
              #profile.address3=validated_data['address3']
            #  print(&quot;1&quot;,profile)
              #print(profile.Gender)
              #print(profile.email)
              #print(profile.dateofbirth)
              profile.save()
              print(&quot;2&quot;,profile)
              print(profile.name)
              print(&quot;save done&quot;)
  
              return instance
  </code></pre>
  <p>//views.py</p>
  <pre><code>class ProfileCreateAPIView(CreateAPIView):
     
      def put(self, request, *args, **kwargs):
          print(&quot;my print 0&quot;,request)
          header_token = request.META.get('HTTP_AUTHORIZATION', None)
          print(header_token)
          access_token=header_token.split(' ')[1]
          status,user =validate_token(access_token)
          print(request.data)
          
          
          user_profile_serializer = UserProfileSerializer(
                      instance=user,
                  data=request.data
          )
          user_serializer = UserSerializer(
                  instance=user,
                  data=request.data)
          print(&quot;my print 1&quot;,user_profile_serializer.is_valid())
          print(&quot;my print 2&quot;,user_serializer.is_valid())
          if user_profile_serializer.is_valid() and user_serializer.is_valid():
              user_profile_serializer.save()
              print(&quot;user_profile save done&quot;)
              user_serializer.save()
              print(&quot;user save done&quot;)
  
              return Response(
                      status=rt_status.HTTP_200_OK)
          # Combine errors from both serializers.
        #  errors = dict()
         # errors.update(user_profile_serializer.errors)
          #errors.update(user_serializer.errors)
          else:
              return Response(status=rt_status.HTTP_400_BAD_REQUEST)
          '''
          return Response(status=rt_status.HTTP_400_BAD_REQUEST)
          '''
  </code></pre>
  <p>Now the issue is  when i am hitting the api I am getting user_serializer.is_valid() as TRUE but False from UserProfile.
  I feel there is some issue with my getting the  profile data.
  But I am not able to understand how to resolve the issue .
  Any help is much appreciated.</p>