Two Django projects with common models and business logic

135 views
Skip to first unread message

andy

unread,
Dec 23, 2014, 1:22:03 PM12/23/14
to django...@googlegroups.com

Hi,

I have two Django Projects that have different use cases. There are reached using different domains. They are hosted in two different servers. Also each Django project has it's own database.

Now, both the projects have some models and some business logic common between them. I don't want to duplicate the code and data which shall be chaotic going forward. Also, I want the models and code (business logic) to be in sync (when models/code is altered).

Can anyone guide me towards a pattern that can help me attain the required architecture: 2 separate projects with common models and business logic.

Thanks in advance.

/andy

P.S. This is my first post. So pardon me for breaking any forum etiquette.

Javier Guerra Giraldez

unread,
Dec 23, 2014, 2:11:25 PM12/23/14
to django...@googlegroups.com
On Tue, Dec 23, 2014 at 1:22 PM, andy <andy...@gmail.com> wrote:
> Now, both the projects have some models and some business logic common
> between them. I don't want to duplicate the code and data which shall be
> chaotic going forward. Also, I want the models and code (business logic) to
> be in sync (when models/code is altered).


encapsulate those models and code in reusable apps. and since Django
apps are just Python modules, you can package and deploy them using
Python tools like pip.

--
Javier

andy

unread,
Dec 24, 2014, 11:18:43 AM12/24/14
to django...@googlegroups.com
Thank you. Since it's only me that'd be using the apps do can I bypass the 'deploy using pip' thing and somehow directly use it in my other projects?

/andy

Javier Guerra Giraldez

unread,
Dec 24, 2014, 11:26:22 AM12/24/14
to django...@googlegroups.com
On Wed, Dec 24, 2014 at 11:18 AM, andy <andy...@gmail.com> wrote:
> Thank you. Since it's only me that'd be using the apps do can I bypass the
> 'deploy using pip' thing and somehow directly use it in my other projects?


you could just set links or add to your `sys.path` list, but that
makes it hard not to break one project when developing the other.

a little better is to use your version control system, so now you have
(at least) three projects: project A, project B and a common app, each
on a different repository. each server would checkout not only the
project-specific code but also the common app

--
Javier

Vijay Khemlani

unread,
Dec 24, 2014, 11:26:38 AM12/24/14
to django...@googlegroups.com
You can version it under a different repository, clone it in each server, and then add that path to the PYTHONPATH of each project, or just make a symbolic link to the app.



--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users...@googlegroups.com.
To post to this group, send email to django...@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/4448040a-6db8-4558-ac30-e559d57fce6c%40googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

Stefano Probst

unread,
Dec 25, 2014, 1:09:51 PM12/25/14
to django...@googlegroups.com
If you use Git as VCS: Use submodules. Submodules allow foreign repositories to be embedded within a dedicated subdirectory of the source tree, always pointed at a particular commit. Quote from the link:
It often happens that while working on one project, you need to use another project from within it. Perhaps it’s a library that a third party developed or that you’re developing separately and using in multiple parent projects. A common issue arises in these scenarios: you want to be able to treat the two projects as separate yet still be able to use one from within the other.

Collin Anderson

unread,
Dec 29, 2014, 12:38:01 AM12/29/14
to django...@googlegroups.com
Hi All,

Another option which no one mentioned yet would be to keep all of the code for _both_ projects in the same repo and share common code that way.

Collin
Reply all
Reply to author
Forward
0 new messages