On Sat, Oct 8, 2016 at 2:52 AM, hans.krebs42 <hans.kreb...@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.



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+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
For more options, visit https://groups.google.com/d/optout.

Reply via email to