Skip to content

Instantly share code, notes, and snippets.

@oliverroick
Created March 7, 2016 15:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save oliverroick/030d3240c8520e00c51d to your computer and use it in GitHub Desktop.
Save oliverroick/030d3240c8520e00c51d to your computer and use it in GitHub Desktop.
class ProjectSerializer(DetailSerializer, ModelSerializer):
users = UserSerializer(many=True, read_only=True)
organization = OrganizationSerializer(read_only=True)
class Meta:
model = Project
fields = ('id', 'organization', 'country', 'name', 'description',
'archived', 'urls', 'contacts', 'users')
read_only_fields = ('id', 'country',)
detail_only_fields = ('users',)
def create(self, validated_data):
organization = self.context['organization']
return Project.objects.create(
organization_id=organization.id,
**validated_data
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment