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
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.
Thanks everyone.
Yoo