Added presentation
This commit is contained in:
parent
7dfe29b10d
commit
74ff118612
|
|
@ -48,10 +48,23 @@ class BaseModel( models.Model ):
|
||||||
await sync_to_async(lambda: [ getattr(self, f) for f in fields ])()
|
await sync_to_async(lambda: [ getattr(self, f) for f in fields ])()
|
||||||
|
|
||||||
|
|
||||||
def fields_to_dict( self, *fields ):
|
_model_dict_presentations = {}
|
||||||
|
@classmethod
|
||||||
|
def dict_presentation( cls, name ):
|
||||||
|
def attacher_decorator( f ):
|
||||||
|
cls._model_dict_presentations[name] = f
|
||||||
|
return f
|
||||||
|
return attacher_decorator
|
||||||
|
|
||||||
|
def fields_to_dict( self, *fields, presentation_name = None ):
|
||||||
"""
|
"""
|
||||||
To create json/dict from fields.
|
To create json/dict from fields.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
if presentation_name:
|
||||||
|
assert presentation in self._model_dict_presentations, f"This model '{self.__class__}' does not have a '{presentation_name}' presentation!"
|
||||||
|
fields.extend( self._model_dict_presentations[presentation_name] )
|
||||||
|
|
||||||
results = {}
|
results = {}
|
||||||
for f in fields:
|
for f in fields:
|
||||||
name, method = (f[0], f[1]) if isinstance(f, tuple) else (f, f)
|
name, method = (f[0], f[1]) if isinstance(f, tuple) else (f, f)
|
||||||
|
|
|
||||||
2
setup.py
2
setup.py
|
|
@ -2,7 +2,7 @@ from setuptools import setup, find_packages
|
||||||
|
|
||||||
setup(
|
setup(
|
||||||
name='asyncron',
|
name='asyncron',
|
||||||
version='0.1.6',
|
version='0.1.7',
|
||||||
packages=find_packages(),
|
packages=find_packages(),
|
||||||
#include_package_data=True, # Include static files from MANIFEST.in
|
#include_package_data=True, # Include static files from MANIFEST.in
|
||||||
install_requires=[
|
install_requires=[
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user