2013-06-18 22:49:01 +02:00
|
|
|
from rest_framework import serializers
|
2019-01-05 11:27:15 +01:00
|
|
|
from .models import EventParticipation, Event
|
2013-06-18 22:49:01 +02:00
|
|
|
|
|
|
|
|
|
|
|
class ParticipationSerializer(serializers.ModelSerializer):
|
2019-01-05 11:27:15 +01:00
|
|
|
event = serializers.PrimaryKeyRelatedField(many=False, read_only=False, queryset=Event.objects.all())
|
|
|
|
user = serializers.Field(source='get_username')
|
|
|
|
status = serializers.CharField(source='status', required=False)
|
|
|
|
|
2013-06-18 22:49:01 +02:00
|
|
|
def get_identity(self, data):
|
2013-10-14 19:46:53 +02:00
|
|
|
""" This hook is required for bulk update. """
|
2013-06-18 22:49:01 +02:00
|
|
|
try:
|
2014-06-20 12:24:01 +02:00
|
|
|
return data.get('event', None), data.get('user')
|
2013-06-18 22:49:01 +02:00
|
|
|
except AttributeError:
|
|
|
|
return None
|
|
|
|
|
|
|
|
class Meta:
|
|
|
|
model = EventParticipation
|
2013-09-26 21:56:32 +02:00
|
|
|
fields = ('event', 'user', 'status', 'comment')
|