Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6859483
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T02:17:21+00:00 2026-05-27T02:17:21+00:00

Assuming I have entries in a datastore that reference other datastore entities: id link

  • 0

Assuming I have entries in a datastore that reference other datastore entities:

id    link    val_1    val_2
-----------------------------
1      None      10    None
2       1       None     4
3       2       None     5
4       3       None     2
etc...  etc...  etc...   etc...

I need to recursively progress through the datastore doing the following:

1. Get entry 1 via get_by_id(1);
2. Get val_1 from entry 1
3. Query db for any entries that have '1' as the link.
4. With the results, add entry 1's val_1 to their val_2 and update their val_1
   with the result
5. For each result, query db for other entries that have their 'link' set to the
   results id, add the result's val_1 to their val_2 and update their val_1
6. Query db for any entries that have the result's id as their link
7. Repeat from step 5

I’ve tried to translate this into python, but I’m getting nowhere. Does anyone have some ideas on how I can accomplish this?

edit: I got the following code to do what I need. I feel that it could be refactored significantly. Any suggestions?

def updateLinked(cid):
    c = Info.get_by_id(int(cid))
    q = Info.all()
    q.filter('link =',int(cid))
    result = q.fetch(1000)
    for item in result:
        linked = 1

        new_link_id = item.key().id()
        val_2 = item.val_2
        val_1 = c.val_1 + val_2

        item.val_1 = val_1
        item.put()

        while linked == 1:
            q2 = Info.all()
            q2.filter('link=',new_link_lid)
            result2 = q2.fetch(1000)

            if len(result2):    
                linked = 1
                for item2 in result2:
                    c = Info.get_by_id(new_link_id)
                    new_link_id = item2.key().id()

                    val_2 = item2.val_2
                    val_1 = c.val_1 + val_2

                    item2.val_1 = val_1
                    item2.put()
            else:
                linked = 0
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T02:17:21+00:00Added an answer on May 27, 2026 at 2:17 am

    Looks like you are essentially pushing an update out across a hierarchical dataset. Consider using either GAE’s built in parent/ancestor functionality or rolling your own by adding a db.ListProperty(db.Key) to your model that includes a list of all ‘link’ record keys. This would save you considerable time by allowing you to query all the data that needs to be updated in one go.

    class Info(db.Model):
        link = db.SelfReferenceProperty()
        val_1 = db.IntegerProperty()
        val_2 = db.IntegerProperty()
        ancestors = db.ListProperty(db.Key) #list of ancestor links
    
    def updateLinked(cid):
        c = Info.get_by_id(int(cid))
        result = Info.all().filter('ancestors = ', c.key())
        for item in result:
            item.val_1 = c.val_1 + item.val_2
            item.put()
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Assuming I have a schema that describes a root element class Root that contains
I have a working perl script that grabs the data I need and displays
Assuming Visual C/C++ 6, I have a complex data structure of 22399 elements that
I have a list of timesheet entries that show a start and stop time.
I'm compiling a lookup table that needs to have 133,784,560 entries, with values ranging
We have a small project that involves automatically parsing some server/mail logs (among other
Assuming I have only the class name of a generic as a string in
Assuming I have an open source web server or proxy I can enhance, let's
Assuming I have three tables : TableA (key, value) TableB (key, value) TableC (key,
Assuming I have a tree structure UL --LI ---INPUT (checkbox) And I want to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.