views:

231

answers:

2

My code looks as such:

def add_cart(request):
    return create_object(request, form_class=CartForm,
    post_save_redirect=reverse('test.views.show_cart',
                               kwargs=dict(object_id='%(key)s')))

Ideally, I would like it to look like so:

def add_cart(request):
    newobject = create_object(request, form_class=CartForm,
    post_save_redirect=reverse('test.views.show_cart',
                               kwargs=dict(object_id='%(key)s'))) 
    request.session['cartid'] = newobject.key
    return newobject

How can I retrieve the key from the newly created object?

I am using google-app-engine-patch with all the latest versions.

A: 

Under Django you can either use

newobject.id

or

newobject.pk

I recommend using .pk.

Remember that newobject.pk isn't always the same as newobject.id.

Gonzalo
A: 

The current generic views, create_object included, don't provide hooks to do extra processing with the created object. So if you want to do this you'll have to roll your own create view, which really isn't very hard.

When Django 1.2 rolls around we should get class-based generic views, which will make it a lot easier to hook in extra bits of functionality.

Carl Meyer