added back lost code: safe and unsafe str
This commit is contained in:
@@ -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 ):
|
||||||
|
|||||||
Reference in New Issue
Block a user