Django: Referencing the pk in a multi form view
I have a view with two forms. I am trying to reference the uploaded image's pk in the same form. How do i do that?
form1 = ImageForm(request.FILES, request.POST)
form2= SongFor开发者_StackOverflowm(request.POST or None)
if form2.is_valid() and form1.is_valid():
image = form1.save(commit=False)
image.save()
save_file(request.FILES['image'])
song = form2.save(commit=False)
song.image = the uploaded image's pk???
song.save()
Thanks,
Once you call image.save()
image should get a pk, and therefore, you should be able to reference it with image.pk
.
精彩评论