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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T18:33:42+00:00 2026-05-13T18:33:42+00:00

I have the following models: class Author(db.Model): name = db.StringProperty() class Story(db.Model): author =

  • 0

I have the following models:

class Author(db.Model):
    name = db.StringProperty()

class Story(db.Model):
    author = db.ReferenceProperty(Author)

What’s the raw GQL to find all Stories by a certain author. In regular SQL, I will use joins but I don’t think that’s available in GQL.

Edit:

I’m looking for the raw GQL way, I know how to do it the Pythonic way. For instance something like(the following is probably totally wrong):

"SELECT * FROM Story WHERE author = :1", "Shakespeare"

I want to run the above from the GAE admin Data > Data Viewer > Query the Datastore. I want the raw SQL that someone could run from a typical mysql or psql shell.

  • 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-13T18:33:42+00:00Added an answer on May 13, 2026 at 6:33 pm

    Edit2: Ah, the raw-GQL for use in the data-viewer…
    Here’s one way:

    1) Run this and get the ID number:

    SELECT * FROM Author where name = 'shakespeare'
    

    2) Using ID number from previous query, run this:

    SELECT * FROM Story where author = key('Author', 12345)
    

    Edit: at long last, the raw GQL:
    (Easiest way: Use the implicit backreference property name; in the form “modelname_set”.)

    qry = GqlQuery("SELECT * FROM Author WHERE name = :1", "shakespeare")
    shakespeare = qry.get()
    shakespeare.story_set # this property now contains all Shakespeare's stories
    

    or

    qry0 = GqlQuery("SELECT * FROM Author WHERE name = :1", "shakespeare")
    shakespeare = qry0.get()
    
    qry1 = GqlQuery("SELECT * FROM Story WHERE author = :1", shakespeare.key())
    shakespeare_stories = qry1.fetch(10) # probably good to have some limit here
    

    I prefer this way:

    qry = Author.all()
    qry.filter('name = ', 'shakespeare')
    shakespeare = qry.get()
    
    shakespeare.story_set # this property now contains all Shakespeare's stories
    

    The more involved way may sometimes be necessary:

    qry0 = Author.all()
    qry0.filter('name = ', 'shakespeare')
    shakespeare = qry0.get()
    
    qry1 = Story.all()
    qry1.filter('author = ', shakespeare.key())
    shakespeare_stories = qry1.fetch(10) # probably good to have some limit here
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following two models class Author(Model): name = CharField() class Publication(Model): title
I have the following models (details are omitted): class Author(models.Model): name = models.CharField('name', max_length=200,
I have the following Django and Flex code: Django class Author(models.Model): name = models.CharField(max_length=30)
I have the following models class Person(models.Model): name = models.CharField(max_length=100) class Employee(Person): job =
I have the following models: class City(models.Model): name = models.CharField(max_length=100) class Pizza(models.Model): name =
I have following models setup in my Django application class School(models.Model): name = models.TextField()
I have the following models: class Author(models.Model): author_name = models.CharField() class Book(models.Model): book_name =
I have the following models class Book(models.Model): name = models.CharField(max_length=140) class UserProfile(models.Model): favorites =
I have following models relation: class Section(models.Model): section = models.CharField(max_length=200, unique=True) name = models.CharField(max_length=200,
I have following two models class Questionnaire(models.model) name = models.CharField(max_length=128, null=True, blank=True) type =

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.