views:

28

answers:

1

Hello!

I'm using google appengine and Django. I'm using de djangoforms module and wanted to specify the form instance with the information that comes from the query below.

    userquery = db.GqlQuery("SELECT * FROM User WHERE googleaccount = :1", users.get_current_user())

    form = forms.AccountForm(data=request.POST or None,instance=?????)

I've found a snippet in a sample app that does this trick, but I can't modify it to work with the query I need.

    gift = User.get(db.Key.from_path(User.kind(), int(gift_id)))
    if gift is None:
         return http.HttpResponseNotFound('No gift exists with that key (%r)' %
                                   gift_id)
    form = RegisterForm(data=request.POST or None, instance=gift)

Could anyone help me?

+2  A: 

If you know the userquery will only have one User object in it (or if you only care about the first one if there are duplicates), you can modify your code like so:

userquery = db.GqlQuery("SELECT * FROM User WHERE googleaccount = :1", users.get_current_user())
user = userquery.get() # Gets the first User instance from the query, or None
form = forms.AccountForm(data=request.POST or None, instance=user)
Will McCutchen