Skip to content

Instantly share code, notes, and snippets.

@syfun
Created June 26, 2018 02:51
Show Gist options
  • Save syfun/455820a619352f674d47288bd3bcbbe4 to your computer and use it in GitHub Desktop.
Save syfun/455820a619352f674d47288bd3bcbbe4 to your computer and use it in GitHub Desktop.
class UserSerializer(serializers.ModelSerializer):
profile = ProfileSerializer()
class Meta:
model = User
fields = ('username', 'email', 'profile')
def create(self, validated_data):
profile_data = validated_data.pop('profile')
user = User.objects.create(**validated_data)
Profile.objects.create(user=user, **profile_data)
return user
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment