In the old DB (db.Model
), you would have to specify key_name
when creating an instance.
In the new DB (ndb.Model
), you need to specify id
, otherwise an incremented integer is chosen.
So calling function testing
twice yields four different Statistic
instances with IDs 1, 2, 3 and 4.
If you explicitly specify a different ID for each Statistic
instance, then you will get only two instances.
I believe that in your case, you might as well remove the team_id
field:
class Statistic(ndb.Model):
qty_customers = ndb.IntegerProperty()
Then, specify a unique ID for every Statistic
instance that you create:
def testing():
Statistic(id = 2, qty_customers = 600).put()
Statistic(id = 3, qty_customers = 5).put()
BTW, I think that it is recommended to use string IDs rather than integer IDs:
def testing():
Statistic(id = '2', qty_customers = 600).put()
Statistic(id = '3', qty_customers = 5).put()
UPDATE:
Even if you're calling function testing
in your application only once, GAE often creates and destroys the application instance itself. So each time a new instance of your application is created, a new pair of Statistic
instances are also created. If these instances are not already in the database, then they are added to it when you call function put
(and that's why you need to specify an ID for each instance).