Fixed shared dict presentation

This commit is contained in:
Oracle 2025-05-05 11:27:15 +02:00
parent 60ac1a49cc
commit e2995273cc

View File

@ -48,10 +48,13 @@ 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 ])()
_model_presentations = {}
@classmethod @classmethod
def presentation( cls, name ): def presentation( cls, name ):
def attacher_decorator( f ): 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 cls._model_presentations[name] = f
return f return f
return attacher_decorator return attacher_decorator
@ -63,6 +66,7 @@ class BaseModel( models.Model ):
if presentation_name: 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!" assert presentation_name in self._model_presentations, f"This model '{self.__class__}' does not have a '{presentation_name}' presentation!"
fields = list(fields) fields = list(fields)
fields.extend( self._model_presentations[presentation_name].fields ) fields.extend( self._model_presentations[presentation_name].fields )