Created
June 26, 2018 02:51
-
-
Save syfun/455820a619352f674d47288bd3bcbbe4 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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