mirror of
https://github.com/encode/django-rest-framework.git
synced 2025-08-02 19:40:13 +03:00
Update serializers.md
The class UserSerializer shows that the User model has a foreign key of a profile. Whereas when creating an object of a profile in the code it was written as Profile.objects.create(user=user, **profile_data) which means profile has a foreign key of users.
This commit is contained in:
parent
7d64b7016d
commit
df4ed21717
|
@ -312,8 +312,8 @@ The following example demonstrates how you might handle creating a user with a n
|
||||||
|
|
||||||
def create(self, validated_data):
|
def create(self, validated_data):
|
||||||
profile_data = validated_data.pop('profile')
|
profile_data = validated_data.pop('profile')
|
||||||
user = User.objects.create(**validated_data)
|
profile = Profile.objects.create(**profile_data)
|
||||||
Profile.objects.create(user=user, **profile_data)
|
user = User.objects.create(profile=profile, **validated_data)
|
||||||
return user
|
return user
|
||||||
|
|
||||||
#### Writing `.update()` methods for nested representations
|
#### Writing `.update()` methods for nested representations
|
||||||
|
|
Loading…
Reference in New Issue
Block a user