title: How do I edit my serializer create() method to make relationship to nested object in Django REST Framework?
body: <p>In my app, Groups are created by Users</p>
  <pre><code>class UserSerializer(serializers.ModelSerializer):
      class Meta:
          model = User
          fields = [&quot;user_id&quot;, &quot;username&quot;]
  
  
  class GroupSerializer(serializers.ModelSerializer):
      owner = UserSerializer()
  
      class Meta:
          model = Group
          fields = [&quot;name&quot;, &quot;picture_url&quot;, &quot;owner&quot;, &quot;members&quot;]
  
      def create(self, validated_data):
          owner_data = validated_data.pop(&quot;owner&quot;)
          user = User.objects.filter(user_id=owner_data.get(&quot;user_id&quot;))
          instance = Group.objects.create(**validated_data)
          instance.owner = user
          instance.save
          return instance
  </code></pre>
  <p>I'm trying to have it so that I can create a Group object, which can only have an existing User as its owner (I need to do this by the user_id, which is separate from the id), but somehow when I post the following:</p>
  <pre><code>    &quot;owner&quot;: {
          &quot;user_id&quot;:6
      },
      &quot;picture_url&quot;:&quot;nothing&quot;,
      &quot;name&quot;:&quot;jazz club&quot;
  }
  </code></pre>
  <p>It returns this:</p>
  <pre><code>{
      &quot;owner&quot;: {
          &quot;user_id&quot;: [
              &quot;user with this user id already exists.&quot;
          ],
          &quot;username&quot;: [
              &quot;This field is required.&quot;
          ]
      }
  }
  </code></pre>
  <p>For context, my post method looks like this:</p>
  <pre><code>    def post(self, request):
          new_group = request.data
          new_group[&quot;members&quot;] = []
          serializer = self.serializer_class(data=new_group)
          serializer.is_valid(raise_exception=True)
          serializer.save()
  
          return Response(serializer.data, status=status.HTTP_201_CREATED)
  </code></pre>
  <p>And my models look like this:</p>
  <pre><code>class User(models.Model):
      id = models.BigAutoField(primary_key=True, unique=True)
      user_id = models.BigIntegerField(unique=True)
      username = models.CharField(max_length=100)
  
  
  class Group(models.Model):
      name = models.CharField(max_length=255, unique=True)
      picture_url = models.CharField(max_length=255)
      owner = models.ForeignKey(
          User,
          on_delete=models.CASCADE,
          related_name=&quot;owned_groups&quot;,
          blank=True,
      )
      members = models.ManyToManyField(User, related_name=&quot;groups&quot;, blank=True)
  </code></pre>
  <p>What do I need to change to make this work? I've tried a lot of different stuff.</p>