Created
March 7, 2016 15:59
-
-
Save oliverroick/030d3240c8520e00c51d to your computer and use it in GitHub Desktop.
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
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