开发者

Django: Referencing the pk in a multi form view

开发者 https://www.devze.com 2023-03-05 13:19 出处:网络
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?

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消