Django Forum App Project Structure
Question: **EDIT: I'm new to this site but if you are going to down vote me, could you
perhaps explain why? I've searched Google, this site and others but have not
found anything that makes any sense and I thought this was a site to ask
questions and get some help.**

I've got a Custom PHP Forum that I am trying to convert to Python/Django as a
learning experience and I'm having some problems. I've been reading up on
Django and it is encouraged that our application is split into multiple apps.
I went through the 6 part tutorial and many other parts of the documentation
but I'm left with some questions.

Let's assume that I have about 30 tables.

Tables such as: posts_index, posts, users, user_groups, user_activity,
user_sessions, forums, payment_gateways, payment_logs, etc for a basic forum

I'm having issues structuring my models. With PHP all I needed was index.php,
/admin/index.php, view_forum.php, view_thread.php and a few others, everything
could pull directly from the database and I had no issues but now I have to
deal with apps/modules.

I'm thinking I'd need to structure my apps in a manner similar to this:

    
    
    /admin/ app
    /forums/ app
    /view_forum/ app
    /view_thread/ app
    /forums/view_forum/ app (instead of just /view_forum/, could be a sub app)
    /forums/view_thread/ app (instead of /view_thread/, could be a sub app)
    

**My problem and only question here is dealing with global state. For example
Users/Group/Session/Logging/Permission information is going to need to be
shared across multiple apps through importing in the other apps models file.
To do this I need to reference their model information, what is the correct
way to handle this?**

Would either of these be acceptable?

  1. Create a ton of different apps such as /users/ which would model my users_groups, users, user_sessions, another app for /posts/ that would include models for posts_index, forums, and so forth with these models existing but not actually being used publicly, they would be used in other apps only. They would be imported in areas such as the /view_forum/ app since when viewing a forum I might need to determine if the user is logged in, is a member of a particular group, etc and because of that would need access to a number of the hidden apps and hence would be imported from the hidden app.

  2. What if I just had one single app, instead of it being an app it would just be my entire project. This sounds like the best solution to me but it seems to be suggested if we cannot summarize the entire application into a sentence it needs to be broken up. If I went with one single app being used as my entire project, my models file will have 30+ different models, is this acceptable? I assume not but figured I'd ask. 

Do either of the above make any sense? If not what would you do fix it? I'll
admit I'm lost so any feedback would mean a lot.

I'm new to Python/Django and am trying to figure things out. I hope I am clear
on what I am trying to do. I'm more than welcome to any advice. I've been
trying to play around with things but I figure it would be better to ask for
advice from more experienced developers. I'm not a professional programmer and
am still learning so please be nice :).


Answer: I have voted this up... I had similar questions when I first moved to Django
(also coming from PHP)

Try not to think of apps in terms of db tables (or url paths), you want to
create apps for independent pieces of functionality.

I would say most of your code will be in a single `forum` app with `Forum` and
`Post` models in it and all your forum-related urls like `/view_forum/` and
`/view_thread/`. Note there's not really such thing as a sub-app in Django...
these are different views which all belong to one related set of functionality
in a single app.

The 'users' stuff... you normally want to hook in to the Django auth system
(<https://docs.djangoproject.com/en/dev/topics/auth/default/#user-objects>)
though if you are trying to keep the legacy database structure this may be
harder... you may end up needing your own `users` app.

The payment gateways stuff sounds like another app again.

For the admin, you get this (almost) for free with Django:  
<https://docs.djangoproject.com/en/1.5/ref/contrib/admin/>  
You need an `admin.py` inside each app, where you register the models that you
want to expose to the admin site.

You might find it's best to follow a tutorial and build a simple blog (or try
and build a very simple minimal forum from scratch) to get a feel for Django
before tackling your re-write. Because trying to exactly recreate the old
functionality with legacy db tables will be a bit harder and may lead you into
patterns which are not 'good Django'.

You might also find it useful to look at the source code of an existing Django
forum app, such as this one:  
<https://bitbucket.org/slav0nic/djangobb/src/>  
They have just a single `djangobb_forum` app that does everything. I think
this is entirely justified as a forum is a single complicated piece of
functionality.

Note how their `Profile` model effectively extends the built-in Django
`auth.User` model via a `OneToOneField`. It makes it easier to integrate with
the built-in login and authentication system that way.

