Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You are never using <strong>fetch()</strong> to actually execute the GqlQuery that you create in line 80.</p> <p>Try this:</p> <pre><code>country_wide_data = db.GqlQuery("SELECT * FROM CountryWideData WHERE country = :1 AND questionNo = :2", user_country, question_number).fetch() </code></pre> <p>By the way, you are going to want to do this incrementing inside of a transaction; otherwise, you will get a race condition if more than one request can execute this code, and the counts will be inaccurate. The documentation on transactions is here: <a href="http://code.google.com/appengine/docs/python/datastore/transactions.html" rel="nofollow noreferrer">http://code.google.com/appengine/docs/python/datastore/transactions.html</a></p> <p>Generally, you are going to want to take the code that creates or updates these entities and put them into functions, like this:</p> <pre><code>def increment_existing_data(key, answered): cwd_to_incr = db.get(key) if answered == 1: cwd_to_incr.optionOne += 1 elif answered == 2: cwd_to_incr.optionTwo += 1 cwd_to_incr.put() def create_new_data(answered, user_country, question_number): new_data = CountryWideData(country=user_country, questionNo=question_number) if answered == 1: new_data.optionOne = 1 new_data.optionTwo = 0 elif answered == 2: new_data.optionOne = 0 new_data.optionTwo = 1 new_data.put() </code></pre> <p>Then, you can call these functions using the <strong>db.run_in_transacation</strong> method, like this:</p> <pre><code>country_wide_data = db.GqlQuery("SELECT * FROM CountryWideData WHERE country = :1 AND questionNo = :2", user_country, question_number).get() if country_wide_data is not None: db.run_in_transaction(increment_existing_data, country_wide_data.key(), answered_option) else: db.run_in_transaction(create_new_data, answered_option, user_country, question_number) </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload