[QRTR-78] Fixed up some Account and User formatting in the API, added separate post vs get Account method, and fixed plaid_client auth token bug.
This commit is contained in:
parent
1a13b3f7c5
commit
076e7ec15f
32
api/mixins.py
Normal file
32
api/mixins.py
Normal file
@ -0,0 +1,32 @@
|
|||||||
|
class ReadWriteSerializerMixin(object):
|
||||||
|
"""
|
||||||
|
Overrides get_serializer_class to choose the read serializer
|
||||||
|
for GET requests and the write serializer for POST requests.
|
||||||
|
|
||||||
|
Set read_serializer_class and write_serializer_class attributes on a
|
||||||
|
viewset.
|
||||||
|
"""
|
||||||
|
|
||||||
|
read_serializer_class = None
|
||||||
|
write_serializer_class = None
|
||||||
|
|
||||||
|
def get_serializer_class(self):
|
||||||
|
if self.action in ["create", "update", "partial_update", "destroy"]:
|
||||||
|
return self.get_write_serializer_class()
|
||||||
|
return self.get_read_serializer_class()
|
||||||
|
|
||||||
|
def get_read_serializer_class(self):
|
||||||
|
assert self.read_serializer_class is not None, (
|
||||||
|
"'%s' should either include a `read_serializer_class` attribute,"
|
||||||
|
"or override the `get_read_serializer_class()` method."
|
||||||
|
% self.__class__.__name__
|
||||||
|
)
|
||||||
|
return self.read_serializer_class
|
||||||
|
|
||||||
|
def get_write_serializer_class(self):
|
||||||
|
assert self.write_serializer_class is not None, (
|
||||||
|
"'%s' should either include a `write_serializer_class` attribute,"
|
||||||
|
"or override the `get_write_serializer_class()` method."
|
||||||
|
% self.__class__.__name__
|
||||||
|
)
|
||||||
|
return self.write_serializer_class
|
||||||
Loading…
Reference in New Issue
Block a user