How to change the default property on a set in python and Google AppEngine
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)
精彩评论