- c - 在位数组中找到第一个零
- linux - Unix 显示有关匹配两种模式之一的文件的信息
- 正则表达式替换多个文件
- linux - 隐藏来自 xtrace 的命令
下面的代码
class Translation(db.Model):
origin = db.ReferenceProperty(Expression, required=True)
target = db.ReferenceProperty(Expression, required=True)
产生以下错误:
Traceback (most recent call last): File "C:\Program Files (x86)\Google\google_appengine\google\appengine\tools\dev_appserver.py", line 4053, in _HandleRequest self._Dispatch(dispatcher, self.rfile, outfile, env_dict) File "C:\Program Files (x86)\Google\google_appengine\google\appengine\tools\dev_appserver.py", line 3977, in _Dispatch base_env_dict=env_dict) File "C:\Program Files (x86)\Google\google_appengine\google\appengine\tools\dev_appserver.py", line 588, in Dispatch base_env_dict=base_env_dict) File "C:\Program Files (x86)\Google\google_appengine\google\appengine\tools\dev_appserver.py", line 3050, in Dispatch self._module_dict) File "C:\Program Files (x86)\Google\google_appengine\google\appengine\tools\dev_appserver.py", line 2954, in ExecuteCGI reset_modules = exec_script(handler_path, cgi_path, hook) File "C:\Program Files (x86)\Google\google_appengine\google\appengine\tools\dev_appserver.py", line 2834, in ExecuteOrImportScript exec module_code in script_module.dict File "D:\svn\language\Web\src\controller.py", line 5, in from model import * File "C:\Program Files (x86)\Google\google_appengine\google\appengine\tools\dev_appserver.py", line 1505, in Decorate return func(self, *args, **kwargs) File "C:\Program Files (x86)\Google\google_appengine\google\appengine\tools\dev_appserver.py", line 2450, in load_module return self.FindAndLoadModule(submodule, fullname, search_path) File "C:\Program Files (x86)\Google\google_appengine\google\appengine\tools\dev_appserver.py", line 1505, in Decorate return func(self, *args, **kwargs) File "C:\Program Files (x86)\Google\google_appengine\google\appengine\tools\dev_appserver.py", line 2339, in FindAndLoadModule description) File "C:\Program Files (x86)\Google\google_appengine\google\appengine\tools\dev_appserver.py", line 1505, in Decorate return func(self, *args, **kwargs) File "C:\Program Files (x86)\Google\google_appengine\google\appengine\tools\dev_appserver.py", line 2282, in LoadModuleRestricted description) File "D:\svn\language\Web\src\model.py", line 24, in class Translation(db.Model): File "C:\Program Files (x86)\Google\google_appengine\google\appengine\ext\db__init__.py", line 500, in init _initialize_properties(cls, name, bases, dct) File "C:\Program Files (x86)\Google\google_appengine\google\appengine\ext\db__init__.py", line 415, in _initialize_properties attr.property_config(model_class, attr_name) File "C:\Program Files (x86)\Google\google_appengine\google\appengine\ext\db__init__.py", line 3461, in property_config self.collection_name)) DuplicatePropertyError: Class Expression already has property translation_set
如何规避这个限制?
最佳答案
给出不同的集合名称
class Translation(db.Model):
origin = db.ReferenceProperty(Expression, required=True,collection_name='origin_translation_set')
target = db.ReferenceProperty(Expression, required=True,collection_name='target_translation_set')
默认情况下,每个 db.ReferenceProperty 在引用模型中创建一个名为 referencedmodelname_set 的集合。
例如:
class OwnedCar(db.Model):
brand = db.StringProperty(required=True)
owner = db.ReferenceProperty(Human, required=True)
class Human(db.Model):
name = db.StringProperty(required=True)
drives = db.ReferenceProperty(reference_class=Car)
默认情况下,每个人都会有一个名为 ownedcar_set 的属性。如果您两次引用同一模型,则会产生 collection_name 冲突。所以你应该添加 collection_name 来区分集合。
更多引用here
关于python - 如何从另一个模型引用同一个模型两次?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6126045/
我是一名优秀的程序员,十分优秀!