开发者

How to change the default property on a set in python and Google AppEngine

开发者 https://www.devze.com 2022-12-14 13:42 出处:网络
In the following code: class ClassA(db.Model): name = db.StringProperty() class ClassB(db.Model): name = db.StringProperty()

In the following code:

class ClassA(db.Model):
    name = db.StringProperty()

class ClassB(db.Model):
    name = db.StringProperty()
    deleted_flag = db.BooleanProperty()
    classA = db.ReferenceProperty(ClassA)

ClassA will have a property called classb_set. When I call classb_set within code, I do not wan开发者_JAVA技巧t it to return items that have the deleted_flag = true.

How can I change the default filter on the classb_set query? My first instinct is to create another method in ClassA that does this filter, but is there a way that keeps the classb_set a property?


You can always use a Python property to accomplish your goal:

class ClassA(db.Model):
    name = db.StringProperty()

    def __get_classBdeleted(self):
        return self.classB_set.filter('deleted_flag =', 'True')

    classBdeleted = property(__get_classBdeleted)

class ClassB(db.Model):
    name = db.StringProperty()
    deleted_flag = db.BooleanProperty()
    classA = db.ReferenceProperty(ClassA)
0

精彩评论

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