title: DjangoRestFramework - How to access other fields of a OneToOneField reverse relationship using a model serializer?
body: <p>I am using the default User model and am also extending it with a UserExtended model:</p>
  
  <pre><code>class Country(models.Model):
      countryName = models.CharField(max_length=50, unique=True)
      countryCode = models.CharField(max_length=10, unique=True)
  
  class UserExtended(models.Model):
      user = models.OneToOneField(User, related_name="userextended")
      country = models.ForeignKey(Country)
  </code></pre>
  
  <p>I am trying to follow what is documented here: <a href="http://www.django-rest-framework.org/api-guide/relations/#reverse-relations" rel="noreferrer">http://www.django-rest-framework.org/api-guide/relations/#reverse-relations</a></p>
  
  <p>This is my UserSerializer:</p>
  
  <pre><code>class UserSerializer(serializers.ModelSerializer):
  
      def __init__(self, *args, **kwargs):
              super(UserSerializer, self).__init__(*args, **kwargs) # call the super() 
              for field in self.fields: # iterate over the serializer fields
                  self.fields[field].error_messages['required'] = 'Enter a valid %s.'%field # set the custom error message
  
      class Meta:
          model = User
          fields = ('username', 'password', 'email', 'userextended')
  
          extra_kwargs = {
                      'password': {
                          'write_only': True,
                      }
                  }
  
      def create(self, validated_data):
          user = User.objects.create_user(
              email = validated_data['email'],
              username = validated_data['username'],
              password = validated_data['password'],
          )
          return user
  </code></pre>
  
  <p>My issue is, if the end user does not fill out the "Country" section of the form before submitting it, Django sends an error message to the front end saying "Enter a valid userextended". "userextended" is the name of the reverse relationship, and every user object is linked to a userextended object and vise-versa. "userextended" is mandatory, but the end user does not have to specify a "userextended" field when creating a user object because that is already a given (the moment the end user creates a user object, the user object will have a reverse relationship with a UserExtended object by default). </p>
  
  <p>The end user has to fill out a "Country" section in the form because Country is what is required from the end user. With that said, how do I get Django to say "Enter a valid Country" rather than "Enter a valid userextended"?</p>
  
  <p>If the end user successfully saves a user object, and submits "Canada" in the "Country" section in the form, how does DRF know to save "Canada" as the country? Because currently, it looks like DRF thinks the "Country" section in the form refers to the "userextended" reverse relationship field.</p>
  
  <p>What I'd expect is, in the "fields" array for the user serializer, I use dot notation? Something like this?:</p>
  
  <pre><code>fields = ('username', 'password', 'email', 'userextended.country')
  </code></pre>
  
  <p>Edit: I just created a UserExtended serializer as well, like so:</p>
  
  <pre><code>class UserExtendedSerializer(serializers.ModelSerializer):
  
      class Meta:
          model = UserExtended
          fields = ('country')
  </code></pre>
  
  <p>but I don't know how to "merge" this serializer with the original UserSerializer.</p>