EventSpecificSerializer provides event attribute
This commit is contained in:
parent
771fdf878e
commit
d19e5978b6
1 changed files with 15 additions and 14 deletions
|
@ -3,14 +3,28 @@ from rest_framework import serializers
|
|||
from event.models import Event, ActivityTag, Place, ActivityTemplate
|
||||
|
||||
|
||||
# Event Serializer
|
||||
class EventSerializer(serializers.HyperlinkedModelSerializer):
|
||||
created_by = serializers.ReadOnlyField(source='created_by.username')
|
||||
|
||||
class Meta:
|
||||
model = Event
|
||||
fields = ('url', 'id', 'title', 'slug', 'created_by', 'creation_date',
|
||||
'description', 'beginning_date', 'ending_date')
|
||||
|
||||
|
||||
# Classes utilitaires
|
||||
class EventSpecificSerializer(serializers.ModelSerializer):
|
||||
"""
|
||||
Provide `update` and `create` methods for nested view with an Event
|
||||
For example for Models which exetends EventSpecificMixin
|
||||
For example for Models which extends EventSpecificMixin
|
||||
the event id has to be provided in the `save` method
|
||||
Works fine with view.EventSpecificViewSet
|
||||
Also provides :
|
||||
event = eventserializer(allow_null=true, read_only=true)
|
||||
"""
|
||||
event = EventSerializer(allow_null=True, read_only=True)
|
||||
|
||||
def update(self, instance, validated_data):
|
||||
"""
|
||||
Note : does NOT change the event value of the instance
|
||||
|
@ -30,19 +44,8 @@ class EventSpecificSerializer(serializers.ModelSerializer):
|
|||
|
||||
|
||||
# Serializers
|
||||
class EventSerializer(serializers.HyperlinkedModelSerializer):
|
||||
created_by = serializers.ReadOnlyField(source='created_by.username')
|
||||
|
||||
class Meta:
|
||||
model = Event
|
||||
fields = ('url', 'id', 'title', 'slug', 'created_by', 'creation_date',
|
||||
'description', 'beginning_date', 'ending_date')
|
||||
|
||||
|
||||
# TODO rajouter des permissions
|
||||
class PlaceSerializer(EventSpecificSerializer):
|
||||
event = EventSerializer(allow_null=True, read_only=True)
|
||||
|
||||
class Meta:
|
||||
model = Place
|
||||
fields = ('url', 'id', 'name', 'description', 'event')
|
||||
|
@ -50,8 +53,6 @@ class PlaceSerializer(EventSpecificSerializer):
|
|||
|
||||
# TODO rajouter des permissions
|
||||
class ActivityTagSerializer(EventSpecificSerializer):
|
||||
event = EventSerializer(allow_null=True, read_only=True)
|
||||
|
||||
class Meta:
|
||||
model = ActivityTag
|
||||
fields = ('url', 'id', 'name', 'is_public', 'color', 'event')
|
||||
|
|
Loading…
Reference in a new issue