From 78dfb3c2d6134ea7fdd76d77f9e71a85a48d6451 Mon Sep 17 00:00:00 2001 From: Queue A Date: Thu, 4 Jun 2026 11:59:28 +0200 Subject: [PATCH] added back lost code: safe and unsafe str --- asyncron/base/models.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/asyncron/base/models.py b/asyncron/base/models.py index e7820d3..d0d0ed7 100644 --- a/asyncron/base/models.py +++ b/asyncron/base/models.py @@ -1,5 +1,6 @@ from django.db import models from django.contrib.contenttypes.fields import GenericRelation +from django.core.exceptions import SynchronousOnlyOperation from asgiref.sync import sync_to_async from asyncron.utils import rgetattr @@ -47,6 +48,17 @@ class BaseModel( models.Model ): if 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 def presentation( cls, name ):