django models = business logic + data access? Or data access layer should be separated out from django model?

后端 未结 2 1901

In Django, the suggested software architecture is to put all business logic and data access in models.

But, some colleagues have suggested that the data access layer sho

2条回答
  •  不要未来只要你来
    2021-02-02 16:15

    The answer depends on the requirements of your application.

    For applications which will always use relational databases and can be coupled with a specific ORM, you do not need to separate data access and models. Django ORM is based on the active record design pattern, which supposes data access and model are together. Pro is simplicity, con is less flexibility.

    Separating data access and model is only necessary when developer wants to uncouple completely data access layer and business logic. You can do it with the data mapper design pattern. Some ORMs support this design pattern, such as SQLAlchemy. Pro is more flexibility, con is more complexity.

    I recommend the book "Patterns of Enterprise Application Architecture" written by Martin Fowler for more details.

提交回复
热议问题