本文介绍了Google App Engine中的自引用ReferenceProperty的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



有趣的是,我试图建立一个文件夹/文件夹模型,文件系统,但无法获取文件夹引用文件夹。



我的第一次尝试是这样的:

  class Folder(db.Model):
id = db.StringProperty()
name = db.StringProperty()
created = db.DateTimeProperty(auto_now_add = True )
folder = db.ReferenceProperty(Folder,collection_name =folders)

但那失败,因为当试图定义文件夹时未定义文件夹。



我也尝试在主要声明之外定义文件夹,如下所示:

  class Folder(db.Model):
id = db.StringProperty()
name = db.StringProperty()
created = db.DateTimeProperty(auto_now_add = True)

Folder.folder = db.ReferenceProperty(Folder,collection_name =folder s)

但是失败的原因是:
AttributeError:'Folder'对象没有任何属性'folders'



我很难过。有没有人有此经验,或解决这个问题?

方案

这正是 SelfReferenceProperty

a>是为。


I'm having a bit of trouble with ReferencePropertys in App Engine (Python).

For a bit of fun, I'm trying to model a folder/file system, but having trouble getting folders to reference folders.

My first attempt was this:

class Folder(db.Model):
    id = db.StringProperty()
    name = db.StringProperty()
    created = db.DateTimeProperty(auto_now_add=True)
    folder = db.ReferenceProperty(Folder, collection_name="folders")

But that fails as "Folder" isn't defined when "folder" is trying to be defined.

I've also tried defining "folder" outside of the main declaration for "Folder", like so:

class Folder(db.Model):
    id = db.StringProperty()
    name = db.StringProperty()
    created = db.DateTimeProperty(auto_now_add=True)

Folder.folder = db.ReferenceProperty(Folder, collection_name="folders")

But that fails with: AttributeError: 'Folder' object has no attribute 'folders'

I'm kind of stumped. Does anyone have experience with this, or a solution to this problem?

Thanks in advance.

解决方案

That's exactly what SelfReferenceProperty is for.

这篇关于Google App Engine中的自引用ReferenceProperty的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-28 21:38