Where should django manager code live?

前端 未结 4 2039
无人及你
无人及你 2021-02-01 18:15

This is a pretty simple django patterns question. My manager code usually lives in models.py, but what happens when models.py is really huge? Is there any other alternative patt

4条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2021-02-01 18:52

    I prefer to keep my models in models.py and managers in managers.py (forms in forms.py) all within the same app. For more generic managers, I prefer to keep them in core.managers if they can be re-used for other apps. In some of our larger apps with models/modelname.py that will contains a manager and the model code which doesn't seem bad.

提交回复
热议问题