On Google AppEngine what is the best way to merge two tables?

Posted by gpjones on Stack Overflow See other posts from Stack Overflow or by gpjones
Published on 2009-08-18T19:00:18Z Indexed on 2010/04/21 9:03 UTC
Read the original article Hit count: 198

Filed under:
|

If I have two tables, Company and Sales, and I want to display both sets of data in a single list, how would I do this on Google App Engine using GQL?

The models are:


class Company(db.Model):

   companyname = db.StringProperty()          
   companyid = db.StringProperty()
   salesperson = db.StringProperty()

class Sales(db.Model):

   companyid = db.StringProperty()

   weeklysales = db.StringProperty()

   monthlysales = db.StringProperty()

The views are:


def company(request): 
  companys = db.GqlQuery("SELECT * FROM Company")   
  sales = db.GqlQuery("SELECT * FROM Sales") 
  template_values = {
    'companys' : companys,
    'sales' : sales
  } 
  return respond(request, 'list', template_values)

List html includes:


{%for company in companys%}  
  {% for sale in sales %}    
    {% ifequal company.companyid sales.companyid %} 

    {{sales.weeklysales}}
    {{sales.monthlysales}}

    {% endifequal %}
     {% endfor %}

          {{company.companyname}}
          {{company.companyid}}
          {{company.salesperson}}

{%endfor%}

Any help would be greatly appreciated.

© Stack Overflow or respective owner

Related posts about python

Related posts about google-app-engine