views:

52

answers:

1

Let's say I have an user registration form. In this form, I have the option for the user to upload a photo. I have an User table and Photo table. My User table has a "PathToPhoto" column. My question is how do I fill in the "PathToPhoto" column if the photo is uploaded and inserted into Photo table before the user is created? Another way to phrase my question is how to get the newly uploaded photo to be associated to the user that may or may not be created next.

I'm using python and postgresql.

A: 

To make sure we're on the same page, is the following correct?

  • You're inserting the photo information into the Photo table immediately after the user uploads the photo but before he/she submits the form;
  • When the user submits the form, you're inserting a row into the User table;
  • One of the items in that row is information about the previously created photo entry.

If so, you should be able to store the "path to photo" information in a Python variable until the user submits the form, and then use the value from that variable in your User-table insert.

DLosc
Yes, all your points are correct. I was thinking the same thing with the variable but wasn't sure if there are alternate solutions where a third table needs to be created. But i think this is probably the best solution. Thanks.
teggy