14👍
✅
Use depth=1
in your Meta
class of serializer,
class ProfileSerializer(serializers.ModelSerializer):
class Meta:
model = Profile
fields = (
'id',
'user',
'synapse',
'bio',
'profile_pic',
'facebook',
'twitter'
)
depth = 1
👤JPG
3👍
You can create a UserSerializer
and use it in ProfileSerializer
like this(using as nested serializer):
class UserSerializer(serializers.ModelSerializer):
class Meta:
model = User
fields = (
'username',
'first_name',
# and so on..
)
class ProfileSerializer(serializers.ModelSerializer):
user = UserSerializer(read_only=True)
class Meta:
model = Profile
fields = (
'id',
'user',
'synapse',
'bio',
'profile_pic',
'facebook',
'twitter'
)
- [Django]-PHP and Django: Nginx, FastCGI and Green Unicorn?
- [Django]-Django Multiple Levels Choices for Field
- [Django]-Django(Python) AttributeError: 'NoneType' object has no attribute 'split'
Source:stackexchange.com