Django project structure

57 views
Skip to first unread message

André Meyer-Vitali

unread,
Feb 4, 2016, 4:05:28 PM2/4/16
to Django users
Dear Django Developers

There's quite some confusion here about the best way to structure a Django project.

I'm developing a photography related web site with a news section (based on the poll tutorial) and a contest app (among others). The contest app should be reused every month for a new contest. How does this work? What need to change? The  templates, app, database? I hope that the app does not need to change, but how can the monthly instances be accessed separately? So far, I couldn't find information and examples for more complicated web sites. Where can I find this?

Thanks for your insights!
André

Carl Meyer

unread,
Feb 4, 2016, 4:31:52 PM2/4/16
to django...@googlegroups.com
Hi André,
I recommend simply modifying your contest app so that it knows about
multiple contests, not just one. That would be the usual way to approach
this.

(Django does have the "url namespace" feature, which lets you mount
multiple "instances" of an app's urlconf at different URLs, but that
feature doesn't do anything for you at the model or database layer, so
all the "instances" of the app would still share the same data. So I
doubt that this feature actually helps with your problem. Personally,
I've never actually found a good use case for url namespaces, outside of
contrib.admin.)

Carl

signature.asc

André Meyer-Vitali

unread,
Feb 4, 2016, 4:47:51 PM2/4/16
to Django users
Thanks for your reply, Carl.

How would I modify my contest app so that it knows about multiple contests? Database models (and queries), templates, forms, urls need to be adapted, I guess. Is it sufficient to add an ID to the models such that a specific month's data can be selected, for example?

Is there an example to check out somewhere?

Cheers
André

Carl Meyer

unread,
Feb 4, 2016, 4:56:10 PM2/4/16
to django...@googlegroups.com
Hi André,

On 02/04/2016 02:47 PM, André Meyer-Vitali wrote:
> How would I modify my contest app so that it knows about multiple
> contests? Database models (and queries), templates, forms, urls need to
> be adapted, I guess. Is it sufficient to add an ID to the models such
> that a specific month's data can be selected, for example?
>
> Is there an example to check out somewhere?

These are hard questions to answer without knowing more about your
contest app: how it works currently, what it does, what models it has,
and how you want it to work with a new contest each month.

I would imagine something like having a Contest model (maybe with a
start_date field and an end_date field?), so you can create a new
Contest anytime you want, and then having any other models in the app
all link (with a ForeignKey) to the Contest model, so all their
instances are specific to one Contest. That would be the more flexible
approach.

But I suppose if you are sure that you want "one contest each month" and
that's it, no more flexibility is needed, you could just add date fields
to some of the other models and then modify your queries to select only
objects for the current month?

Carl

signature.asc

André Meyer-Vitali

unread,
Feb 4, 2016, 5:06:49 PM2/4/16
to Django users
Hi Carl

That's a great idea. So, I think the idea is to make the model flexible enough that it can be used in multiple contexts. The rest follows, accordingly.

I'll give it a try. Thanks a lot for the inspiration!

Cheers
André


On Thursday, 4 February 2016 22:05:28 UTC+1, André Meyer-Vitali wrote:
Reply all
Reply to author
Forward
0 new messages