Take the tour ×

Suppose I want to query and display all the images that the user just uploaded through a form on the previous page (multiple images are uploaded at once, each is made into a separate object in the db).

What's the best way to do this?

Since the view for uploading the images is different from the view for displaying the images, how does the second view know which images were part of that upload? I thought about creating and saving the image objects in the first view, gathering the pks, and passing them to the second view, but I understand that it is bad practice. So how should I make sure the second view knows which primary keys to query for?

share|improve this question
add comment

2 Answers

up vote 2 down vote accepted

This is what sessions are for - you'd store the pk's into the session, and then read them back out on the next page.

share|improve this answer
This looks like the solution I might be looking for. Can you think of any problems if the user uses the upload page more than once in any given session? Wouldn't it return all the pks uploaded thus far in that session? –  sgarza62 Jan 16 at 21:06
That's up to you! On the next page, you could clear out those values from the session when you retrieve them, or you could append to them - it's your call. –  girasquid Jan 16 at 21:09
Good idea, thanks! –  sgarza62 Jan 16 at 21:11
add comment

What other fields are there in the model db? You could add an upload_id, which is set automatically after uploading, send it to the next view, and query for that in the db.

share|improve this answer
I thought about doing that, but how would I "send it to the next view"? –  sgarza62 Jan 16 at 21:02
What are the images for? Album or some kind of product? Would be easier if you posted your view function. However, I think girasquid's solution might be the best one –  rulzart Jan 16 at 21:15
another thing: the page that displays the images - is it only a "preview"? Or has the images actually been saved to the db at that point –  rulzart Jan 16 at 21:17
Thanks for your answer. The images have already been resized by PIL and saved. It's not a preview, but rather a page to add a title and a caption to each image object. (To answer your previous comment the images are uploaded to a user's photo library on a site, but I don't think that affects this) –  sgarza62 Jan 16 at 21:23
add comment

Your Answer


