Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Django Structures: Many apps VS one large app

I hope this is not a opinion based question but more like a solutions to a complicated django website. fyi, i am quite a beginner in django.

first of all, i am doing a complicated accounting django website where there are features like:

  • purchases (purchase order, quotation request, quotation, invoice, do)

  • Custom user roles and permissions, because we want user to setup their own roles and permissions system

  • sales (POS, stocks, too many to mentions)

  • user and registrations

  • incomes & expenses tracking and reporting.

There are articles and SO's answers about 'many apps vs 1 large app'. My confusion started. I figured out django allows seperating views.py and models.py into multiple file in app/views and app/models with init.py imports.

I personally do not like large app file as it is hard to locate things. I prefer neat structures. But the confusion keeps attacking. I want to do one thing and do it well but it seem like having one large app makes more sense because all the mentioned features are ForeignKey dependent.

So, according to your experience. what's your ideal folder structures and solutions to deal with this?

If you could provide performance difference that would be helpful.

UPDATE: Since most people said multi apps, I have last question regarding this. Since Django app can have models/ & views/ folder with multiple models.py & views.py inside, that means one large app can be seperated into multiple views files inside a views/ folder. What yall think about this? since this will put all migrations in one place, does it provide long term safety in term of messy things like foreign keys across apps.

like image 280
Loonb Avatar asked Oct 27 '25 12:10

Loonb


1 Answers

This kind of question I have asked long time back, on different platform. Common answer is

If you want to reuse that, then create an app or if you don't want then you no need to make a separate app

Let me give you an example. If your project has features like

  • Sharing an Image
  • Sharing text
  • Comment on Media and Text
  • Upvote and Downvote options

Here an user can share either a image or text and other can comment on it or Upvote/Downvote it. In this case If you make Comment a separate app and Upvote/Downvote a separate app, then in future if you have to add Video along with Image and Text, then all you have to link Video to Comment app and Upvote/DOwnvote app, that will be less task comparing to a big app with all things inside. Also You can manage your database accordingly.

In your case, you can make (for example),

  • Custom User (help you add extra permission in future)
  • Product Category (help you to add more category or subcategory)
  • Products or Sales etc.

For many admins, when you add those apps to your settings.py, and if you edit admin.py separately in each app, everything will appear your admin panel without any hassle.

For many views, you can import all the models to views.py of any app or use it separately in their apps. It will not cause any problem. Same for urls.py and forms.py etc.

like image 88
Bidhan Majhi Avatar answered Oct 30 '25 02:10

Bidhan Majhi



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!