我可以在不同的应用程序中为不同的型号指定相同的名称吗?
我可以在不同的应用程序中为不同的型号指定相同的名称吗?会发生什么冲突?
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)