#importing models from one project to another project

12 messages · Page 1 of 1 (latest)

frosty sky
#

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.

flint gate
#

Are you using relative imports?

frosty sky
#

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.

flint gate
#

It's the same database?

void charm
#

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

rigid star
# frosty sky nope i'm using absolute import. like when im importing i have specified the full...

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.

frosty sky
frosty sky
frosty sky
flint gate
rigid star
#

If required to make CRUD changes @frosty sky