Last active
September 14, 2017 10:42
-
-
Save unpluggedcoder/d30a9c0cf06672e4d93e9a96cec297a5 to your computer and use it in GitHub Desktop.
Use corresponding serializer class for different request method in Django Rest Framework - Part 2
This file contains 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
# serializers.py | |
from rest_framework import serializers | |
from myapp import models | |
class OrganizationListViewSerializer(serializers.ModelSerializer): | |
class Meta: | |
model = models.Organization | |
fields = '__all__' | |
class UserListViewSerializer(serializers.ModelSerializer): | |
org = OrganizationListViewSerializer() | |
class Meta: | |
model = models.User | |
fields = '__all__' | |
class UserCreateUpdateSerializer(serializers.ModelSerializer): | |
org = serializers.PrimaryKeyRelatedField( | |
queryset=models.Organization.objects.all()) | |
class Meta: | |
model = models.User | |
fields = '__all__ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment