views:

36

answers:

1

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 want 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?

+3  A: 

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)
Adam Crossland