Reputation: 43
I have a basic class:
class Post (db.Model):
title = db.StringProperty(required = True)
text = db.TextProperty(required = True)
created = db.DateTimeProperty(auto_now_add = True).
new_record = Post(title = "TESSSST", text = "TESSST")
new_record.put() #works!
And it is works fine - the instances are created and the data is written. But as soon as I remove "required=true" property is no longer stored in the datastore:
class Post (db.Model):
title = db.StringProperty(required = True)
text = db.TextProperty
created = db.DateTimeProperty(auto_now_add = True)
new_record = Post(title = "TESSSST")
new_record.text = "Burn conctructor!"
new_record.put() # text property won't be saved
I don't know if it be helpful but when I checking properties via print new_record.__dict__
all values that was assigned by constructor has '_' prefix (like '_title') and other don't have (just 'text').
So the question is "Is it possible to save to datastore non required (and not initialised by constructor) properies?" I couldn't find answer in gae docs.
Upvotes: 1
Views: 93
Reputation: 599956
But you haven't just removed required=True
, you've removed the brackets ()
which instantiate the field. It should be
text = db.TextProperty()
Upvotes: 1