models.py getting huge, what is the best way to break it up?

后端 未结 3 642
情书的邮戳
情书的邮戳 2020-11-29 16:39

Directions from my supervisor: \"I want to avoid putting any logic in the models.py. From here on out, let\'s use that as only classes for accessing the databa

3条回答
  •  无人及你
    2020-11-29 17:26

    I can't quite get which of many possible problems you might have. Here are some possibilities with answers:

    • multiple models in the same file

      Put them into separate files. If there are dependencies, use import to pull in the additional models.

    • extraneous logic / utility functions in models.py

      Put the extra logic into separate files.

    • static methods for selecting some model instances from database

      Create a new Manager in a separate file.

    • methods obviously related to the model

      save, __unicode__ and get_absolute_url are examples.

提交回复
热议问题