django经理代码应该在哪里生活? [英] Where should django manager code live?

查看:126
本文介绍了django经理代码应该在哪里生活?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是一个非常简单的django模式问题。我的管理器代码通常存在于models.py中,但是在models.py真的很大的时候会发生什么?有什么其他的替代模式可以让你的manager代码存在于models.py中以保持可维护性并避免循环导入?

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 pattern to letting your manager code live in models.py for maintainability and to avoid circular imports?

可能会问一个问题,是如此巨大,但让我们假设它的大小和广度的实用性是有道理的。

A question may be asked as to why models.py is so huge, but let's just assume it's size and breadth of utility is justified.

推荐答案

我更喜欢将我的模型保持在模型中.py和managers.py中的管理员(forms.py中的表单)都在同一个应用程序内。对于更多的通用管理人员,如果他们可以重新用于其他应用程序,我更愿意将它们保留在核心管理员中。在我们的一些较大的应用程序中,模型/ modelname.py将包含一个管理员和模型代码似乎不好。

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.

这篇关于django经理代码应该在哪里生活?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆