blechreiz-website/eventplanner/serializers.py

24 lines
627 B
Python
Raw Normal View History

2013-06-18 22:49:01 +02:00
from rest_framework import serializers
from models import EventParticipation
class ParticipationSerializer(serializers.ModelSerializer):
2013-09-26 21:56:32 +02:00
event = serializers.PrimaryKeyRelatedField( many=False, read_only = False )
user = serializers.Field( source='get_username' )
2013-06-18 22:49:01 +02:00
def get_identity(self, data):
""" This hook is required for bulk update. """
try:
2013-09-26 21:56:32 +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')
2013-06-18 22:49:01 +02:00