blechreiz-website/eventplanner/serializers.py

20 lines
702 B
Python
Raw Normal View History

2013-06-18 22:49:01 +02:00
from rest_framework import serializers
from .models import EventParticipation, Event
2013-06-18 22:49:01 +02:00
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)
2013-06-18 22:49:01 +02:00
def get_identity(self, data):
""" This hook is required for bulk update. """
2013-06-18 22:49:01 +02:00
try:
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')