Hi there,
I have many Models, from which one is Workspace
. I made a reference to this Model in settings.py
to use it in otherfile.py
, like below:
#settings.py
WORKSPACE_MODEL = "accounts.Workspace"
Now, when I try to use it in otherfile.py
like below:
#otherfile.py
from django.conf import settings
Workspace = settings.WORKSPACE_MODEL
print(Workspace.objects.all())
I get below error:
'str' object has no attribute 'objects'
Error Full TraceBack is below:
Traceback Switch to copy-and-paste view
/app/.heroku/python/lib/python3.10/site-packages/django/core/handlers/exception.py, line 55, in inner
response = get_response(request) …
Local vars
/app/.heroku/python/lib/python3.10/site-packages/django/core/handlers/base.py, line 197, in _get_response
response = wrapped_callback(request, *callback_args, **callback_kwargs) …
Local vars
/app/.heroku/python/lib/python3.10/site-packages/django/views/generic/base.py, line 84, in view
return self.dispatch(request, *args, **kwargs) …
Local vars
/app/.heroku/python/lib/python3.10/site-packages/django/contrib/auth/mixins.py, line 73, in dispatch
return super().dispatch(request, *args, **kwargs) …
Local vars
/app/.heroku/python/lib/python3.10/site-packages/django/views/generic/base.py, line 119, in dispatch
return handler(request, *args, **kwargs) …
Local vars
/app/apps/accounts/views.py, line 279, in post
status_message = Workspace.objects.invite_workspace_user( …
Local vars
/app/apps/accounts/managers.py, line 118, in invite_workspace_user
return Invitation.objects.send_invite_user_email(invitation, is_workspace_admin = make_admin) …
Local vars
I know some people will suggest me to import the model instead of using it’s reference like below:
from myapp.models import Workspace
print(Workspace.objects.all()
But, the issue is, I am importing classes from this otherfile.py
to models.py
as well. So let’s say I have to use the Workspace
Model in TestClass
in otherfile.py
, then I am also importing this TestClass
in models.py
and if I directly import Workspace
Model in otherfile.py
, I get error of cyclic import from django, which is reasonable and fine for me, that’s why I want to use Workspace
Model’s reference I created in settings.py
.
Any help would be appreciated