开发者

How to define the models with Multiple to Multiple relationship in Google App Engine?

I am writing a Google App Engine application which has a data model with multiple to multiple relationship. I think I am doing it wrong. My data model class definition is:

class Pro开发者_C百科ject(db.Model):
    name = db.StringProperty()
    description = db.TextProperty()
    admin = db.ReferenceProperty(Appuser)
    website = db.LinkProperty()
    members = db.ListProperty(db.key, default=None)
    start_date = db.DateTimeProperty(auto_add_now = True)

class Appuser(db.Model):
    user_id = db.UserProperty()
    fullname = db.StringProperty()
    website = db.LinkProperty()
    involved_projects = db.ListProperty(db.key, default=None)
    current_project = db.ReferenceProperty(Project)

Now whenever I try to run this I get an error stating Appuser is not defined in the file. It happens because the class Appuser is defined after Project. I couldn't change the order as class Appuser also has a ReferenceProperty to class Project I would get a not defined error for Project. Now how to implement this correctly.


A quick fix to the circular reference issue is to drop the referance_class when defining admin in Project (it is not required just a validation really).

class Project(db.Model):
    admin = db.ReferenceProperty()

It's not ideal, but should solve the issue.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜