Note that there are some explanatory texts on larger screens.

plurals
  1. POGoogle app engine database values not incrementing
    text
    copied!<p>Here is some code that is not working how it is supposed to work. Every time the database is queried, I get either a 0 or 1 value for the options, and the values in database do not increment, even though as as you can see, in line 86 and 89, the values are being incremented. Any idea what's going wrong here? I am using Django on Google App engine.</p> <pre><code> user_result = request.POST['json'] 65 user_result = json.loads(user_result) 66 user_country = get_user_country(user_result) 67 question_number = get_question_number(user_result) 68 answered_option = get_answered_option(user_result) 69 70 country_option_1 = 0 71 country_option_2 = 0 72 world_option_1 = 0 73 world_option_2 = 0 74 75 """ 76 Get already existing record for the question for the contry, or create 77 new one and put/update in db 78 """ 79 80 country_wide_data = db.GqlQuery("SELECT * FROM CountryWideData WHERE country = :1 AND questionNo = :2", user_country, question_number) 81 flag = False 82 for i in country_wide_data: 83 flag = True 84 if flag: 85 if answered_option==1: 86 country_wide_data[0].optionOne = country_wide_data[0].optionOne + 1 87 88 elif answered_option==2: 89 country_wide_data[0].optionTwo = country_wide_data[0].optionTwo + 1 90 country_option_1 = country_wide_data[0].optionOne 91 country_option_2 = country_wide_data[0].optionTwo 92 country_wide_data[0].put() 93 else: 94 country_wide_data = CountryWideData(country=user_country, questionNo=question_number) 95 96 if answered_option==1: 97 country_wide_data.optionOne = 1 98 country_wide_data.optionTwo = 0 99 elif answered_option==2: 100 country_wide_data.optionOne = 0 101 country_wide_data.optionTwo = 1 102 country_option_1 = country_wide_data.optionOne 103 country_option_2 = country_wide_data.optionTwo 104 country_wide_data.put() </code></pre>
 

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