getting transaction result from transaction module
<p>I am using Sqlalchemy and PostgreSQL. In my models I have a <code>Product</code> and an <code>Image</code>. I want each product to have multiple images. This is the product submission method:</p>

<pre><code>def submit_product(self, **kwargs):

    product = Product(
        title=kwargs['title'],
        sub_category_id=kwargs['sub_category_id'],
        year_of_production=kwargs['year_of_production'],
        country_of_production=kwargs['country_of_production'],
        quantity=kwargs['quantity'],
        price=kwargs['price'],
        account_id=session.get('account_id', None)
        )


    DBSession.add(product)
    transaction.commit()

    for image in kwargs['images']:
        image = Image(
            product_id= # what should I put here?,
            image=image.file.read()
        )
        DBSession.add(image)
    transaction.commit()
</code></pre>

<p>in the last part that Im adding images to db. I need the <code>product_id</code> to set for the image. but I dont find a way to get it. Is there a way to get results from the transaction so I can find out what id the new product is assigned to? <code>DBSession.add()</code> and <code>transaction.commit()</code> both return <code>None</code>.</p>

<p>After using:</p>

<pre><code>transaction.commit()
</code></pre>

<p>you can use <code>product.id</code>, because changes have been commited. So product has now its id:</p>

<pre><code>for image in kwargs['images']:
    image = Image(
        product_id=product.id, # what should I put here?,
        image=image.file.read()
    )
    DBSession.add(image)
</code></pre>

python sqlalchemy