Skip to content

Commit

Permalink
Merge pull request #1782 from akvo/#1780-update-locations-api
Browse files Browse the repository at this point in the history
[Fixes #1780] Remove 'location_target' from nested update locations in API
  • Loading branch information
KasperBrandt committed Aug 28, 2015
2 parents ca02838 + 86cb0d9 commit 245b53c
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 3 deletions.
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

0 comments on commit 245b53c

Please sign in to comment.