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

  • SEARCH
  • Home
  • 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 5986785
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T22:43:17+00:00 2026-05-22T22:43:17+00:00

I’m using Django-nonrel on Google App Engine and have the following models (they are

  • 0

I’m using Django-nonrel on Google App Engine and have the following models (they are simplified).

class Author(models.Model):
    name = models.CharField()

class Book(models.Model):
    author = models.ForeignKey(Author)
    title = models.CharField()

So, if I query like this,

books = Book.objects.all()

and pass the books to a template, and display them like below,

<ul>
{% for book in books %}
   <li>{{ book.title }}{{ book.author.name }}</li>
{% endfor %}
</ul>

I see bunch of datastore.get at the AppStats because of book.author.name. I thought I should use select_related() when I query books, but obviously django nonrel doesn’t support since there is no JOIN on Google App Engine.

Could anyone teach me how I should deal with this kind of scenario? Should I consider denormalizing my models? It would be appreciated if you tell me how you work with it.

Thanks,
Yoo

  • 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-22T22:43:18+00:00Added an answer on May 22, 2026 at 10:43 pm

    I’ve struggled to find a way of get_value_from_datastore in Django-Nonrel as Abdul said for a few days. But no luck. So I finally asked @wkornewald at Twitter, then he pointed me to use model.<foreignkey>_id.

    Now, I ported Nick’s solution to Django-nonrel. I’m relatively new to Python, so this might not be good coding, but works as I expect.

    def prefetch_refprop(entities, prop_id, prop, filter):
        ref_ids = [getattr(x, prop_id) for x in entities]
        ref_entities = dict((x.id, x) for x in filter(id__in=ref_ids))
        for entity, ref_id in zip(entities, ref_ids):
            setattr(entity, prop, ref_entities[ref_id])
        return entities   
    
    #Usage
    books = Book.objects.filter(...)
    prefetch_refprop(books, 'author_id', 'author', getattr(Author.objects, 'filter'))
    

    Thanks everyone.
    Yoo

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

No related questions found

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.