我可以在不同的应用程序中为不同的型号指定相同的名称吗? [英] Can I give the same name for different Models in different apps?

查看:35
本文介绍了我可以在不同的应用程序中为不同的型号指定相同的名称吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我可以在不同的应用程序中为不同的型号指定相同的名称吗?会发生什么冲突?

Can I give the same name for different Models in different apps? and What conflicts can happen?

尝试之后.我收到此错误:

After I have a try.. I got this Error:

Error: One or more models did not validate:
playlist.playlist: Accessor for field 'user' clashes with related field 'User.playlist_set'. Add a related_name argument to the definition for 'user'.
audio_playlist.playlist: Accessor for field 'user' clashes with related field 'User.playlist_set'. Add a related_name argument to the definition for 'user'.

推荐答案

当然可以.不会有任何冲突,因为表在内部存储为 appname_modelname ;假设您在名为 blog 的应用程序中有一个名为 Post 的模型,在名为 messages Post 的模型>.表格将存储为 blog_post messages_post .另外,这些python类分别命名为 project.blog.models.Post project.messages.models.Post ,因此在这里也没有冲突.

Of course you can do that. There won't be any conflicts because tables are stored internally as appname_modelname; let's say you have a model named Post in an app named blog and a model named Post in an app named messages. Tables will be stored as blog_post and messages_post. Also, the python classes are named project.blog.models.Post and project.messages.models.Post, so no conflict here either.

编辑:此外,为了能够将它们都导入一个文件中,请使用以下命令:

EDIT: Also, to be able to import them both in one file, use something like this:

import blog.models.Post as BlogPost
import messages.models.Post as MessagesPost

(或任何有意义的名称)

(or any names that make sense)

这篇关于我可以在不同的应用程序中为不同的型号指定相同的名称吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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