You are referencing the Level_2_Heading
model directly, without calling all()
to retrieve the records. Level_2_Headings.all()
will return an object that has the ancestor
attribute, so try changing your first q2
to:
q2 = Level_2_Headings.all().ancestor(q.key()).filter("name2 =",heading2).get()