blechreiz-website/eventplanner/serializers.py

26 lines
807 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' )
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:
print "get_identity event:" + str( data.get('event', None) ) + " user " + str( data.get('user') )
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