在Django应用之间共享模型 [英] Sharing models between Django apps

查看:277
本文介绍了在Django应用之间共享模型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我将简要介绍一下Django应用程序的精神和想法,应用程序可以从另一个应用程序中导入模型吗?说,用户统计应用程序将从用户应用程序导入模型,如:from users.models import users

解决方案

重新构建一个没有机会向公众发布的内部应用程序,当然可以做任何你想要的。



如果你正在构建一个内部应用程序,可能会被未来/现在的开发人员使用,但一定要记录应用程序需要正常工作的情况。



如果您正在构建一个公开发布的应用程序,请尽可能保持自己的依赖(并且django内部依赖,即尽可能使用django提供的)。如果您真的需要第三方应用程序工作,或者第三方应用程序会使您的代码更易于管理,那么请确保包含依赖关系,但请务必确保记录所有要求和必要的设置。



在大多数情况下,只要有足够的文档,您几乎可以做任何事情。



I但是,不得不质疑你自己制作的用户的模型与django的内置 auth.User


I will be brief: to work in the spirit and idea of a Django app, it is ok for an app to import models from inside another app ? Say, a User statistics app will import models from a User app something like: from users.models import users

解决方案

If you're building an internal app that has no chance of ever being released to the public, sure, do whatever you want.

If you're building an internal app that has little chance of ever being released to the public, but will possibly be used by future/current developers, sure, but be sure to document what the app needs to work properly.

If you're building an app for public release, try to keep it self-dependent (and django-internals dependent, ie, use what django provides, when possible). If you really need a third-party app to work, or if a third party app would make your code more manageable, then sure, include dependencies, but be doubly sure to document all requirements and necessary setup.

In most cases, you can do almost whatever you want so long as you have sufficient documentation.

I do, however, have to question the sanity of making your own User model that has the same name as django's builtin auth.User.

这篇关于在Django应用之间共享模型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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