added back lost code: safe and unsafe str

This commit is contained in:
Queue A
2026-06-04 11:59:28 +02:00
parent 7061937488
commit 78dfb3c2d6

View File

@@ -1,5 +1,6 @@
from django.db import models from django.db import models
from django.contrib.contenttypes.fields import GenericRelation from django.contrib.contenttypes.fields import GenericRelation
from django.core.exceptions import SynchronousOnlyOperation
from asgiref.sync import sync_to_async from asgiref.sync import sync_to_async
from asyncron.utils import rgetattr from asyncron.utils import rgetattr
@@ -47,6 +48,17 @@ class BaseModel( models.Model ):
if fields: if fields:
await sync_to_async(lambda: [ rgetattr(self, f) for f in fields ])() await sync_to_async(lambda: [ rgetattr(self, f) for f in fields ])()
def __str__( self ):
if hasattr( self, '__str_unsafe__' ):
try: return self.__str_unsafe__()
except SynchronousOnlyOperation: pass
if hasattr( self, '__str_safe__' ):
return self.__str_safe__()
return super().__str__()
@classmethod @classmethod
def presentation( cls, name ): def presentation( cls, name ):