Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Fixes #1780] Remove 'location_target' from nested update locations in API #1782

Merged
merged 3 commits into from
Aug 28, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions akvo/rest/serializers/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
from .project_update import (ProjectUpdateSerializer,
ProjectUpdateExtraSerializer)
from .project_update_location import (ProjectUpdateLocationSerializer,
ProjectUpdateLocationNestedSerializer,
MapProjectUpdateLocationSerializer)
from .publishing_status import PublishingStatusSerializer
from .recipient_country import RecipientCountrySerializer
Expand Down Expand Up @@ -93,6 +94,7 @@
'ProjectSerializer',
'ProjectUpdateExtraSerializer',
'ProjectUpdateLocationSerializer',
'ProjectUpdateLocationNestedSerializer',
'ProjectUpdateSerializer',
'ProjectUpSerializer',
'PublishingStatusSerializer',
Expand Down
6 changes: 3 additions & 3 deletions akvo/rest/serializers/project_update.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from rest_framework import serializers
from akvo.rsr.models import ProjectUpdate
from ..fields import Base64ImageField
from .project_update_location import (ProjectUpdateLocationSerializer,
from .project_update_location import (ProjectUpdateLocationNestedSerializer,
ProjectUpdateLocationExtraSerializer)
from .rsr_serializer import BaseRSRSerializer
from .user import UserSerializer
Expand All @@ -18,8 +18,8 @@ class ProjectUpdateSerializer(BaseRSRSerializer):

"""Serializer for project updates."""

locations = ProjectUpdateLocationSerializer(source='locations', many=True, required=False,
allow_add_remove=True)
locations = ProjectUpdateLocationNestedSerializer(source='locations', many=True, required=False,
allow_add_remove=True)
photo = Base64ImageField(required=False, allow_empty_file=True)

class Meta:
Expand Down
8 changes: 8 additions & 0 deletions akvo/rest/serializers/project_update_location.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,14 @@ class Meta:
model = ProjectUpdateLocation


class ProjectUpdateLocationNestedSerializer(ProjectUpdateLocationSerializer):

class Meta(ProjectUpdateLocationSerializer.Meta):
# Exclude the mandatory 'location_target' field, so that it is possible to create a
# project update location at the same time as the project update.
exclude = ('location_target',)


class ProjectUpdateLocationExtraSerializer(ProjectUpdateLocationSerializer):

# Limit update data to its PK, this is needed because of Meta.depth = 2
Expand Down