EventSpecificSerializer is now a mixin
This commit is contained in:
parent
2ac3cd345c
commit
9362d4c1f0
1 changed files with 9 additions and 3 deletions
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue