I'm currently developing my own weblog in Django
. But I've already stucked right in the beginning. So, here is my tree hierarchy:
/pyroot/nemoden/
|~blog/
| |-__init__.py
| |-admin.py
| |-models.py
| |-tests.py
| `-views.py
|+css/
|+images/
|+js/
|~templates/
| |-index.html
| `-postslist.html
|-__init__.py
|-manage.py
|-settings.py
`-urls.py
What I've done is: created new application called blog and described all the models I need for a blog in blog/models.py
(User, Post, Comment, etc.), but then I watched Jeff Hui's
video and realised that it is probably a bad idea and in Django-world
people don't do that... what we do in... PHP-world
using our PHP Frameworks
. I guess it is better to have distinguished Django-applications for Tags, Comments, Users, etc...
So, what I'm asking is:
Is it better to have one model per Django-app? If so, are there some exceptions when I should not create a new Django-app for a model?
I want to go with:
/pyroot/nemoden/
|~blog/ # this is actual application (not a django-application). It uses all the models in views.py, so django-apps becomes just models
| |-__init__.py
| |-tests.py
| `-views.py # all the views (controllers in other frameworks) used by our (well,... my) weblog
|+css/
|+images/
|+js/
|~templates/
| |-index.html
| `-postslist.html
|-__init__.py
|~post/
| |-__init__.py
| |-tests.py
| |-admin.py
| |-models.py # only Post model goes here
| `-views.py
|~tag/
| |-__init__.py
| |-tests.py
| |-admin.py
| |-tag.py # only Tag model goes here
| `-views.py # <---- I don't know why we still need it here!
|-manage.py
|-settings.py
`-urls.py
As you see I cut out models.py
and admin.py
from blog
app, so now blog
app more like the app
or main app
if you wish which uses all the models (django-apps) and mainly consists of views.py
. And I think now we don't need all views.py
in all django-apps
(this one is under a BIG question mark, though - it is just in theory).
Is my approach any good or I will suffer problems invisible for me now, maybe?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…