1

It might be the most dumb question and my apologies for the same but I am confused

I have the following entity:

class Profile(ndb.Model):  
    name = ndb.StringProperty()  
    identifier = ndb.StringProperty()  
    pic = ndb.BlobKeyProperty() # stores the key to the profile picture blob 

I want to delete the "pic" property value of the above entity so that it should look as fresh as if "pic" was never assigned any value. I do not intend to delete the complete entity. Is the below approach correct:

qry = Profile.query(Profile.identifier==identifier) 
result_record_list = qry.fetch()  
if result_record_list:  
    result_record_list[0].pic.delete()  # or result_record_list[0].pic = none # or undefined or null 

I am deleting the actual blob referred by this blob key separately

gsinha
  • 1,165
  • 2
  • 18
  • 43

2 Answers2

3

assign None to it and put it back to the datastore.

result_record_list[0].pic = None
result_record_list[0].put()
Omair Shamshir
  • 2,126
  • 13
  • 23
1

The datastore is an OO schemaless databse. So you can add and remove properties from the the Kind (ndb.Model) without the need of a schema update.

If you also want to cleanup the entities look at this anwser from Guido

Community
  • 1
  • 1
voscausa
  • 11,253
  • 2
  • 39
  • 67