Fixed shared dict presentation
This commit is contained in:
parent
60ac1a49cc
commit
e2995273cc
|
|
@ -48,10 +48,13 @@ class BaseModel( models.Model ):
|
|||
await sync_to_async(lambda: [ getattr(self, f) for f in fields ])()
|
||||
|
||||
|
||||
_model_presentations = {}
|
||||
@classmethod
|
||||
def presentation( cls, name ):
|
||||
def attacher_decorator( f ):
|
||||
#We have to do this here so inherited classes are not sharing the dict below
|
||||
if not hasattr( cls, '_model_presentations' ):
|
||||
cls._model_presentations = {}
|
||||
|
||||
cls._model_presentations[name] = f
|
||||
return f
|
||||
return attacher_decorator
|
||||
|
|
@ -63,6 +66,7 @@ class BaseModel( models.Model ):
|
|||
|
||||
|
||||
if presentation_name:
|
||||
if not hasattr( self.__class__, '_model_presentations' ): self.__class__._model_presentations = {}
|
||||
assert presentation_name in self._model_presentations, f"This model '{self.__class__}' does not have a '{presentation_name}' presentation!"
|
||||
fields = list(fields)
|
||||
fields.extend( self._model_presentations[presentation_name].fields )
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user