From 9362d4c1f06bcbbf44518237fc361ef423ea13fd Mon Sep 17 00:00:00 2001 From: Qwann Date: Thu, 27 Jul 2017 11:50:47 +0200 Subject: [PATCH] EventSpecificSerializer is now a mixin --- api/event/serializers.py | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/api/event/serializers.py b/api/event/serializers.py index cd7ba7a..7eb1319 100644 --- a/api/event/serializers.py +++ b/api/event/serializers.py @@ -15,7 +15,7 @@ class EventSerializer(serializers.HyperlinkedModelSerializer): # Classes utilitaires -class EventSpecificSerializer(serializers.ModelSerializer): +class EventSpecificSerializerMixin(): """ Provide `update` and `create` methods for nested view with an Event For example for Models which extends EventSpecificMixin @@ -46,14 +46,16 @@ class EventSpecificSerializer(serializers.ModelSerializer): # Serializers # TODO rajouter des permissions -class PlaceSerializer(EventSpecificSerializer): +class PlaceSerializer(serializers.ModelSerializer, + EventSpecificSerializerMixin): class Meta: model = Place fields = ('url', 'id', 'name', 'description', 'event') # TODO rajouter des permissions -class ActivityTagSerializer(EventSpecificSerializer): +class ActivityTagSerializer(serializers.ModelSerializer, + EventSpecificSerializerMixin): class Meta: model = ActivityTag fields = ('url', 'id', 'name', 'is_public', 'color', 'event') @@ -85,6 +87,8 @@ class ActivityTemplateSerializer(serializers.ModelSerializer): # pour s'assurer que le get ne foire pas le get si, par exemple, le tag # été modifié entre temps dans la base de donnée (mais pas sur la # classe backbone + for tag_data in tags_data: + tag_data.pop('event', None) tags = [ActivityTag.objects.get_or_create(event=event, **tag_data)[0] for tag_data in tags_data] instance.tags.set(tags) @@ -105,6 +109,8 @@ class ActivityTemplateSerializer(serializers.ModelSerializer): # pour s'assurer que le get ne foire pas le get si, par exemple, le tag # été modifié entre temps dans la base de donnée (mais pas sur la # classe backbone + for tag_data in tags_data: + tag_data.pop('event', None) tags = [ActivityTag.objects.get_or_create(event=event, **tag_data)[0] for tag_data in tags_data] activity_template.tags = tags