views:

26

answers:

1

I am trying to get the most recent data item from the datastore. I am trying to apply the method as explained here but I am getting the object <__main__.Rep object at 0x075F1730> not the item. Can anyone explain what I am doing wrong?

The Model is:

class Rep(db.Model):
    sent = db.StringProperty()
    time = db.DateTimeProperty(auto_now_add=True)

This is the handler:

class Repeater(webapp.RequestHandler):
    def get(self):        
        reps = Rep()
        reps.sent = self.request.get('sentence')
        reps.put()

        s = self.request.get('sentence')             

        query = reps.all()
        last = query.order('-time').get()
        sentences = query

Thanks!

+2  A: 

I don't see anything wrong at all.

<__main__.Rep object at 0x075F1730> is presumably an instance of your Rep class, as expected.

Drew Sears
Thanks. I think the problem is I want to compare "s" -the item entered- to the last item in the datastore "last". But this does not work because "last" is the object and "s" is a string. Does this make sense?
Zeynel
Compare s to last.sent
Drew Sears
Great, thanks. Can you explain why "last" is the object but "last.sent" is a string. I am confused about this.
Zeynel
Rep is a class, last is an instance of the class, and sent is a method. You can find explanations of each concept @ http://en.wikipedia.org/wiki/Object-oriented_programming#Fundamental_concepts_and_features
Drew Sears
+1 for patience
Adam Crossland