Implemented static writable ModelSerializers for all models

This commit is contained in:
Jeremy Stretch
2017-01-31 15:35:09 -05:00
parent e1cd846c9a
commit bb1f97abc2
13 changed files with 251 additions and 140 deletions

View File

@@ -12,18 +12,10 @@ class ServiceUnavailable(APIException):
class WritableSerializerMixin(object):
"""
Returns a flat Serializer from the given model suitable for write operations (POST, PUT, PATCH). This is necessary
to allow write operations on objects which utilize nested serializers.
Allow for the use of an alternate, writable serializer class for write operations (e.g. POST, PUT).
"""
def get_serializer_class(self):
class WritableSerializer(ModelSerializer):
class Meta(self.serializer_class.Meta):
pass
if self.action in WRITE_OPERATIONS:
return WritableSerializer
if self.action in WRITE_OPERATIONS and hasattr(self, 'write_serializer_class'):
return self.write_serializer_class
return self.serializer_class