What i am trying to achieve is getting the user object from the webapp2.cached property.
i have a method defined in my request handler which gives me the current user.
@webapp2.cached_property
def current_user(self):
user_dict = self.auth.get_user_by_session()
return self.auth.store.user_model.get_by_id(user_dict['user_id'])
I want to get the User Object because it is a UserProperty() of one of my models which is as follows:
class CountryImage(db.Model):
image = db.BlobProperty()
user = db.UserProperty()
country = db.ReferenceProperty(Country)
approved = db.BooleanProperty(default=False)
Now when the upload form is posted, everything works fine except for the “user” which shows as “None” in the datastore.
The possible reason i found while i was playing with it in the interactive console was that
the method current_user passes a web cached property and not the actual user object.
For Example:
< webapp2.cached_property object at 0xb46aee8c >
Now my question is what would be the best possible way of retrieving the user object ? Thanks in advance for all your help.
Amyth
PS: EDIT:
following is the code where i am trying to store the image in the datastore:
NewImg = models.CountryImage()
NewImg.image = self.request.get('image')
NewImg.user = self.current_user
NewImg.country = models.Country.all().filter("url_name =", country).get()
continue_url = self.request.url
NewImg.put()
PS:
Just to add i have also tried using “users.get_current_user()” method which also returns “None”
Thanks for your responses, however i have soved this already. In case you are using
Usermodel fromwebapp2_extras(which is an extension to User model fromappengine.api.users) you can get the user as followsor