Answer the question
In order to leave comments, you need to log in
Where in Django to store the business logic of the system?
Many PHP / Java / .Net frameworks have such an object as a service - it allows you to pull models and perform some kind of business processing with them. And in fact, all the code is a view - a layer of services (the services themselves pull the CRUD logic of the models) - a view.
In Django, we have logic at the Model level, Logic in Controllers, Logic in commands (there is no service type object here). And the only obvious solution is to break the application into a bunch of small apps and use applications as indivisible units with logic.
Do I understand correctly that this is the most efficient way to organize code?
Ps I already looked at the question - Logic in models or in view in Django?
Answer the question
In order to leave comments, you need to log in
First, the best practice for Django is fat models / thin controllers. Secondly, nothing prevents you from forming a service layer by separating application logic into separate modules independent of the framework.
No need for fat models, make a service layer.This one will come in handy. True, when using it, your business logic will still depend on Django, but it's still convenient))
I do it like in other frameworks. The logic is in the service files, in the models there is only a model, in the views I pull only services or linking a service to a template.
In my opinion, this is the most canonical approach, because. no matter what framework and language you have - the architecture is the same and it's convenient.
In Django, some people still like to write logic in class based views and then suffer because. cannot trace the logic and sequence of code execution. Even the authors of Django, when using class based views, made a lot of security holes, because. the logic in these files is described inconsistently.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question