Reputation: 69
I've recently started with Django web application development and now I want to put wood behind the arrow.
To do the job properly I started over and started to think of a correct naming convention for my web application. I've read through this blog article.
Until now, I've just created a project called myproject
and the app is called myproject_app
.
I realized, the only thing my myproject_app
does is have the models.py
with the database scheme, so I wondered if that is the way to go, or if I took a wrong turn somewhere.
With the app
having nothing more that the description of my database, it's hard to think of a proper name and not just suffix it with _db
or something like that.
To my question: What code belongs to a Django app and what is the appropriate naming convention for such apps?
edit: I did come by this Stackoverflow question, but it does not cover the code one is supposed to have in the Django app, just like it doesn't cover that in the blog article.
Upvotes: 0
Views: 389
Reputation: 436
I think there is no right answer here. There are guidelines and best practices but that doesn't mean there is only one way to go. As far as the naming conventions go the post you show is pretty accurate.
Now regarding where to put the code. I like to think of apps as a module that solves a specific problem. Keep in mind that those apps are not required to have models.py, views.py and urls.py. That's your call. So all the models related to that problem would be inside that app. Same for the views.
For example, you have a project for an e-commerce with 4 apps.
ecommerce/
core/
models.py
web/
views.py
urls.py
payment/
views.py
urls.py
models.py
Core app might have models that are used by all the apps such as the User model or a Custom User model if you have one. The model of the Product your are selling. No views here since its not showing anything. Web app may contain the general views of the web page: login, register, logout, home, products, etc. Payment app can have the models related to Payments: Orders, PaymentMethods, etc. The views in this app will have the payment process. If you have extra python modules you can place them inside each app using the same logic.
Again, this is a personal opinion. Hope it helps.
Upvotes: 2