Recursive delete in google app engine

前端 未结 4 1165
长发绾君心
长发绾君心 2021-02-09 17:37

I\'m using google app engine with django 1.0.2 (and the django-helper) and wonder how people go about doing recursive delete. Suppose you have a model that\'s something like thi

4条回答
  •  故里飘歌
    2021-02-09 18:16

    If your hierarchy is only a small number of levels deep, then you might be able to do something with a field that looks like a file path:

    daddy.ancestry = "greatgranddaddy/granddaddy/daddy/"
    me.ancestry = daddy.ancestry + me.uniquename + "/"
    

    sort of thing. You do need unique names, at least unique among siblings.

    The path in object IDs sort of does this already, but IIRC that's bound up with entity groups, which you're advised not to use to express relationships in the data domain.

    Then you can construct a query to return all of granddaddy's descendants using the initial substring trick, like this:

    query = Person.all()
    query.filter("ancestry >", gdaddy.ancestry + "\U0001")
    query.filter("ancestry <", gdaddy.ancestry + "\UFFFF")
    

    Obviously this is no use if you can't fit the ancestry into a 500 byte StringProperty.

提交回复
热议问题