generic classes fixed
This commit is contained in:
parent
48f9fd516d
commit
36f038259b
2 changed files with 3 additions and 1 deletions
|
@ -24,11 +24,12 @@ class EventSpecificSerializer(serializers.HyperlinkedModelSerializer):
|
|||
def create(self, validated_data):
|
||||
ModelClass = self.Meta.model
|
||||
event_pk = validated_data.pop('event_pk', None)
|
||||
event = get_object_or_404(Event, id=event_pk)
|
||||
event = event_pk and get_object_or_404(Event, id=event_pk) or None
|
||||
instance = ModelClass.objects.create(event=event, **validated_data)
|
||||
return instance
|
||||
|
||||
|
||||
# Serializers
|
||||
class EventSerializer(serializers.HyperlinkedModelSerializer):
|
||||
created_by = serializers.ReadOnlyField(source='created_by.username')
|
||||
|
||||
|
|
|
@ -37,6 +37,7 @@ class EventSpecificViewSet(ModelViewSet):
|
|||
serializer.save(event_pk=event_pk)
|
||||
|
||||
|
||||
# ViewSets
|
||||
class EventViewSet(ModelViewSet):
|
||||
"""
|
||||
This viewset automatically provides `list`, `create`, `retrieve`,
|
||||
|
|
Loading…
Reference in a new issue