How to refer to the same model twice from another?

Following code

class Translation(db.Model):
    origin = db.ReferenceProperty(Expression, required=True)
    target = db.ReferenceProperty(Expression, required=True)

produces the following error:

Traceback (last last call): 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 the manager base_env_dict = base_env_dict) File" C: \ Program Files (x86) \ Google \ google_appengine \ google \ appengine \ tools \ dev_appserver.py ", line 3050 , in the manager 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, from the import model * 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, full name, 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 the 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 the 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, inpy ", line 24, in class translation (db.Model): File" C: \ Program Files (x86) \ Google \ google_appengine \ google \ appengine \ ext \ db__init __. Py ", line 500, inpy ", line 24, in class translation (db.Model): File" C: \ Program Files (x86) \ Google \ google_appengine \ google \ appengine \ ext \ db__init __. Py ", line 500, ininit     _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: the class expression already has the property translation_set

How to get around this limitation?

+5
source share
3 answers
class Translation(db.Model):
    origin = db.ReferenceProperty(Expression, required=True, collection_name='translation_origins')
    target = db.ReferenceProperty(Expression, required=True, collection_name='translation_targets')
+7
source

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)

owncar_set . , collection_name. , .

+10

Give them different collection names:

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')
+5
source

All Articles