mirror of
https://github.com/HackSoftware/Django-Styleguide.git
synced 2024-11-22 09:36:36 +03:00
Add utils.py
with inline_serializer
implementation
This commit is contained in:
parent
d7bd7f7913
commit
f98cbebe2b
11
utils.py
Normal file
11
utils.py
Normal file
|
@ -0,0 +1,11 @@
|
||||||
|
def create_serializer_class(name, fields):
|
||||||
|
return type(name, (serializers.Serializer, ), fields)
|
||||||
|
|
||||||
|
|
||||||
|
def inline_serializer(*, fields, data=None, **kwargs):
|
||||||
|
serializer_class = create_serializer_class(name='', fields=fields)
|
||||||
|
|
||||||
|
if data is not None:
|
||||||
|
return serializer_class(data=data, **kwargs)
|
||||||
|
|
||||||
|
return serializer_class(**kwargs)
|
Loading…
Reference in New Issue
Block a user