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 8982291
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T20:32:38+00:00 2026-06-15T20:32:38+00:00

I am pretty new in GAE and python. The challenge is to make nested

  • 0

I am pretty new in GAE and python. The challenge is to make nested comments with, for example, 3 levels of identation.
GAE-datastore does half work for us. It stores and outputs nested structure in a needed way.
So let example be quite simple:

  • Parent 1
    • Child 1 of Parent 1
    • Child 2 of Parent 1
      • Child 1 of Child 2
      • Child 2 of Child 2
  • Parent 2
    • Child 1 of Parent 2
      • Child 1 of Child 1
    • Child 2 of Parent 2
      • Child 1 of Child 2

If we keep this hierarchy in datastore (by proper using attribute “parent” when creating entities) we will able to fetch list of entities already sorted in this way:
Parent 1
Child 1 of Parent 1
Child 2 of Parent 1
Child 1 of Child 2
Child 2 of Child 2
Parent 2
Child 1 of Parent 2
Child 1 of Child 1
Child 2 of Parent 2
Child 1 of Child 2

So all we need is just make right identation. In other words we need to pass a parameter to our template for each item. Let call this paremeters 0,1,2. I have solution but I dont like it.
I count value of parameter of ident this way:

ident_value = len(CURREN_ITEM.key().to_path())/2 - 2

(Each level in GAE hierarchy path consists of 2 elements.)

So after fetching model from datastore this cycle is executing:

for model in model_list:            
    new_model_list.append(model) # helper list
    ident_value = len(model.key().to_path())/2 - 2 
    if ident_value>3: ident_value = 3 # max ident = 3
    setattr(new_model_list[i], 'ident', ident_value )
    i += 1  

And then new_model_list is passing to jinja template where class name for each item is assigned based on model.ident value.
Helper list is needed because model is instance of MyModel class that used for saving data in datastore and dont have “ident” attribute.

So the question is: Is there more elegant way to do the same thing?

  • 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-06-15T20:32:39+00:00Added an answer on June 15, 2026 at 8:32 pm

    my solution if somebody needed:

    def nest (flow, root_rep_id_list, deep = 0): 
        msglist = []
        nested_comments = []
        deep += 1 
    
        for rep_id in root_rep_id_list:
            if rep_id in flow:
                msglist.append(flow[rep_id])        
    
        for msg in msglist: 
            nested_comments.append(Nestedobject (msg, nest(flow, msg.replies, deep) if msg.replies else None, deep))
            logging.error(msg.replies)      
        return nested_comments
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm pretty new to PHP, but I decided to try and make a simple
I am pretty new to python and pyramid. I am working on pyramid application
I'm trying to move my gae webapp project to django non-rel. I'm pretty new
Pretty new to Python and have been playing around with lists and the sort
Pretty new to python/programming in general, this is my biggest project yet. I am
I'm pretty new to Python, and haven't been able to find an answer to
Pretty new to rails and I was building my routes to get a nested
Pretty new to Java and also to Mac ... I want to make sure
I'm pretty new to Appscale and GAE . Say I have a web application
Pretty new to MVC and the like. I have a class the looks like

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.