Where does business logic go in Django?

Where does business logic go in Django?

Add the logic as a plain Python Image class, e.g. in a file called image.py . Nothing in Django restricts you from adding logic other than that in the views or models modules. This is a good option if the image logic is a central component of your Django app (e.g. a Image processing app).

What is business logic Django?

The business logic layer prescribes how business objects interact with one another and defines the methods by which these objects can be updated. So where do we put business logic in Django? Here are 4 possible solutions with their pros and cons.

Where to put business logic in a model?

Make sure you controller is only used to route information to the business logic layer. The controller should NOT have business logic directly in it. Any validation needs to be handled by IValidatable on the Model. Any business logic needs to be routed to a separate layer.

Where to put business logic in C #?

Any validation needs to be handled by IValidatable on the Model. Any business logic needs to be routed to a separate layer. The general answer I have is that business logic normally fits into two categories: Object Oriented Business Logic: Gets modeled as objects (in the model), usually injected as repositories.

Where do you put logic in a ViewModel?

You want to keep as much logic out of the ViewModel as possible to keep your code reusable and loosely coupled. My suggestion is to put logic in a service layer instead. This is a middle layer between view model and model (which, in a real object oriented paradigm, should only contains properties).

How to use business logic in MVC Stack Overflow?

The user clicks the “delete” button next to one of the emails, the controller notifies the model to delete entry N, then notifies the view the model has changed. Perhaps the admin’s email should never be removed from the list. That’s a business rule, that knowledge belongs in the model.