Gqlquery for no values ​​in ListProperty

I have this code to find all nodes where property branches are empty.

nobranches=TreeNode.all()

for tree in nobranches:
 if tree.branches == []:

I wanted to find a better, more efficient way to do this. Meathod, where I do not need to retrieve all TreeNodes. I tried TreeNode.all (). Filter (branches = []), but it gives me a message: "BadValueError (" Filtering by lists is not supported "). How can I do something like TreeNode.gql (" WHERE branches =: 1 ', []). Fetch (100). I tried this, but I get "BadValueError: cannot use empty list as property value, property is []". Is there any other effective way?

By the way, this is what TreeNode Like looks like.

class TreeNode(db.Model):
  name = db.StringProperty()
  branches =db.ListProperty(db.Key)

+3
2

, , :

, ListProperty StringListProperty, , .

, .

, , . , .

(, hasbranches = db.BooleanProperty()), . hasbranches = False.

0

: , , , , .

, , . aetycoon - , , :

class TreeNode(db.Model):
  name = db.StringProperty()
  branches = db.ListProperty(db.Key)
  branch_count = aetycoon.DerivedProperty(lambda self: len(self.branches))
+1

Source: https://habr.com/ru/post/1769275/


All Articles