Reputation: 3113
I have two model kinds, CourtDays
and Days:
class CourtDays(db.Model): #parent is Courts
court = db.ReferenceProperty(Courts)
reserveMaxTimeBefore = db.ListProperty(int)
reserveMinTimeBefore = db.ListProperty(int)
day = db.StringProperty()
class Days (db.Model):
court = db.ReferenceProperty(Courts)
startTime = db.ListProperty(int)
endTime = db.ListProperty(int)
startTimeLunch = db.ListProperty(int)
endTimeLunch = db.ListProperty(int)
name = db.StringProperty()
Can I remove the "day" in CourtDays
and the "name" in Days
and instead use key_name="day"
and key_name="name"
for put()ing the two kinds even though "day" and "name" are the seven days of the week? Notice that both CourtDays
and Days
have the same ReferenceProperty (and will have the same parent, too). Also, notice that other CourtDays
and Days will have the same days involved, but for other Courts which are parented and referenced by other CourtLocations.
Also, can the method get_or_insert()
be used to make sure that the CourtDays
or Days
entity for, say "Monday", can be revised but kept unique? I ask because the datastore docs say "The get and subsequent (possible) put operations are wrapped in a transaction to ensure atomicity. Ths means that get_or_insert()
will never overwrite an existing entity, ..." . Despite that phrase and because of it, does this mean that a "Model.get_or_insert (key_name, **kwds)" can be followed by a put()
and overwrite the particular instance?
Upvotes: 1
Views: 214
Reputation: 647
Two entities can have the same key_name if they have different kinds, namespaces or parents. If two keys has same kinds, ids, parents and app_id they both points to the same entity.
I believe that phrase will never overwrite an existing entity means that get_or_insert
will never put entity to datastore if there is an entity with such a key (property values does not metter). And yes, followed put()
will overwrite that instance.
Upvotes: 3