20 lines
702 B
Python
20 lines
702 B
Python
from rest_framework import serializers
|
|
from .models import EventParticipation, Event
|
|
|
|
|
|
class ParticipationSerializer(serializers.ModelSerializer):
|
|
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)
|
|
|
|
def get_identity(self, data):
|
|
""" This hook is required for bulk update. """
|
|
try:
|
|
return data.get('event', None), data.get('user')
|
|
except AttributeError:
|
|
return None
|
|
|
|
class Meta:
|
|
model = EventParticipation
|
|
fields = ('event', 'user', 'status', 'comment')
|