I have two Django projects with distinct responsibilities. In the first project, I handle the core logic for scheduling events. Previously, I pushed Celery tasks related to events directly to the queue. However, I'm now exploring a different approach. I want to store these tasks in a database and fetch them based on conditions in my second project.
To achieve this, I've defined a model in the second project. Now, instead of pushing tasks directly to the queue, I'm using Django ORM to create records for the model in the first project. The challenge arises when I try to import the model from the second project; I encounter import issues. i hope my question is clear. if details needed i can explain you furtherly.
issue: I'm facing difficulties importing the model from Project 2 into Project 1.
#importing models from one project to another project
12 messages · Page 1 of 1 (latest)
Are you using relative imports?
nope i'm using absolute import. like when im importing i have specified the full path the error i got was that the model in second project i have mention is within an app i have specified that app also while importing the error shows up like this app is not being in in the INSTALLED_APPS of settings.py of 1st project. i have included project.app in the installed_apps.
It's the same database?
It may be wise to split the common models out into a third project, then the other two add that as a "third party app".
This sounds a lot like a reusable app
Try importing just by app_name.model name. The apps are already added to your application namespaces. Django should resolve it on it's own.
Like if you have users & blogs app. Then if you need to import users.User model anywhere in blogs, you could just use users.User
Relative or absolute don't work exactly the same for models in django. (one example is how you define AUTH_USER_MODEL setting as "users.UserModel" and not "users.models.UserModel" )
I read about this quite a while ago when I faced the same issue.
no, 1st project is connect to db. 2nd project which i have this model is connected to another db which a shared_db
i have only one common model in my case
but in my case im importing a model from another project not within the same project
I would rewrite the whole model, or use it like a reusable app.
Adding to this, if you decide to rewrite the whole model, use managed = False flag to make it read only. That way, you could just read the data from this project. Accessing the model as a reusable app is a better option.
If required to make CRUD changes @frosty sky