add simple_geometry to location api

This commit is contained in:
Laura Klünder 2017-10-28 21:36:52 +02:00
parent f83b77ed8b
commit 5fe03c4c8e
5 changed files with 30 additions and 12 deletions

View file

@ -83,7 +83,8 @@ class Location(LocationSlug, AccessRestrictionMixin, TitledMixin, models.Model):
result = super().serialize(detailed=detailed, **kwargs)
if not detailed:
result = OrderedDict((
(name, result[name]) for name in ('slug', 'title', 'subtitle')
(name, result[name]) for name in ('id', 'slug', 'title', 'subtitle', 'point', 'bounds', 'locations')
if name in result
))
return result
@ -246,10 +247,12 @@ class LocationGroup(Location, models.Model):
self.orig_category_id = self.category_id
self.orig_color = self.color
def _serialize(self, **kwargs):
result = super()._serialize(**kwargs)
def _serialize(self, simple_geometry=False, **kwargs):
result = super()._serialize(simple_geometry=simple_geometry, **kwargs)
result['category'] = self.category_id
result['color'] = self.color
if simple_geometry:
result['locations'] = tuple(obj.pk for obj in getattr(self, 'locations', ()))
return result
@property