0

I have stored data in the gae datastore, but when I query the data and reference the properties I seem to be getting a reference to the object rather than the value of the attribute.

class ClassDefinitions(db.Model):
    class_name = db.StringProperty
    class_definition = db.TextProperty

class FlexEntityAdminHandler(webapp.RequestHandler):
    def get(self):
        query = db.GqlQuery("SELECT * FROM ClassDefinitions")
        definitions = query.fetch(1000, 0)

        for definition in definitions:
            logging.info("Name: %s", definition.class_name)
            logging.info("Def: %s", definition.class_definition)

When I reference definition.class_name I get:

<class 'google.appengine.ext.db.StringProperty'>

Instead of the value that I stored. I know that it is getting stored because each time I add a new entry the number of results from the query increases by 1. Does anyone know what I'm doing wrong?

1 Answer 1

4

When creating the model, you need to create actual instances of the property type classes:

class ClassDefinitions(db.Model):
    class_name = db.StringProperty()
    class_definition = db.TextProperty()

(Note the ().)

1
  • Thanks, such an obvious mistake but I've been staring at it for hours! Aug 3, 2011 at 13:23

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.