I’m using google app engine and I’m trying to insert a entity/table using the code:
class Tu(db.Model):
title = db.StringProperty(required=True)
presentation = db.TextProperty(required=True)
created = db.DateTimeProperty(auto_now_add=True)
last_modified = db.DateTimeProperty(auto_now=True)
.
.
.
a = Tu('teste', 'bla bla bla bla')
a.votes = 5
a.put()
but I get this error:
TypeError: Expected Model type; received teste (is str)
I’m following this doc https://developers.google.com/appengine/docs/python/datastore/entities and I don’t see where I’m wrong.
When you create a model in that way, you need to use keyword arguments for all attributes of your model. Here is a snippet of the
__init__signature fromdb.Model, from which yourTumodel inherits:When you say
a = Tu('teste', 'bla bla bla bla'), since you aren’t providing keyword arguments and are instead passing them as positional arguments,testeis assigned to theparentargument in the__init__(andbla bla bla blato thekey_name) and since that argument needs an object of typeModel(which I’m assuming you don’t have), you get that error. Assuming you are instead trying to add those items astitleandpresentation, you would say (as @DanielRoseman already succinctly stated 🙂 ):