Multiple instances of a Django application operating on different data

127 views
Skip to first unread message

hans.krebs42

unread,
Oct 8, 2016, 10:07:48 AM10/8/16
to Django users
I'm coding a Django web project. I've created an app and implemented its functionality - templates, models etc. The website needs to use this application in two places, and the only difference are the sets of data the instances will be operating on (for example, say it's a news app and I have two unrelated sections of the site, each needs to display news concerning completely different topics). Is there a clean (i.e. other than just copying all the code into another directory) way to achieve this in Django? Ideally I'd like to use one database and split the data into separate tables.

Vineet Kothari

unread,
Oct 10, 2016, 5:30:51 PM10/10/16
to django...@googlegroups.com
you can use classes refer from here
https://github.com/bmentges/django-cart
and see how he is using cart.py

On Sat, Oct 8, 2016 at 3:22 PM, hans.krebs42 <hans.k...@gmail.com> wrote:
I'm coding a Django web project. I've created an app and implemented its functionality - templates, models etc. The website needs to use this application in two places, and the only difference are the sets of data the instances will be operating on (for example, say it's a news app and I have two unrelated sections of the site, each needs to display news concerning completely different topics). Is there a clean (i.e. other than just copying all the code into another directory) way to achieve this in Django? Ideally I'd like to use one database and split the data into separate tables.

--
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+unsubscribe@googlegroups.com.
To post to this group, send email to django...@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/713754f8-89ec-44cd-92d2-2017035e5cd1%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

James Schneider

unread,
Oct 16, 2016, 7:36:46 PM10/16/16
to django...@googlegroups.com
On Sat, Oct 8, 2016 at 2:52 AM, hans.krebs42 <hans.k...@gmail.com> wrote:
I'm coding a Django web project. I've created an app and implemented its functionality - templates, models etc. The website needs to use this application in two places, and the only difference are the sets of data the instances will be operating on (for example, say it's a news app and I have two unrelated sections of the site, each needs to display news concerning completely different topics). Is there a clean (i.e. other than just copying all the code into another directory) way to achieve this in Django? Ideally I'd like to use one database and split the data into separate tables.

Why do you need separate Django instances for this? Are the two instances meant to stand out on their own as well as provide common content?

If I understand your requirements correctly, it sounds like all you need is a separate set of models that both inherit from the same abstract master model (to achieve table separation with the same fields). The only difference between your views would be the referenced model and the URL (which controls which set of views that are called). If you use CBV's, then you can likely write one view that does all the work, and a second view that inherits from it, only changing the reference model.

If it were me, I would try to combine all of the articles down into a single table, and filter the articles for each section of the site by tags or categories. That would be way easier to keep track of, even when taking advantage of the inheritance in the models and views.

You may also be able to take advantage of the sites framework, but I'm not sure if that achieves what you want (intended for separate databases), however, you could have both instances point at the same database and have a different reference model listed in your settings.py that your views will use. You may have other issues with doing that (most likely with authentication), but it would be something to look into.


-James
Reply all
Reply to author
Forward
0 new messages