2015-12-07 38 views

回答

1

我想你可能要形式的第一保存到一個模型,更新後profile_image

from django.core.files.base import ContentFile 

if form.is_valid(): 
    new_player = form.save() 

    temp_image = new_player.profile_image2 
    # duplicate the image for "profile_image2" 
    dup_file = ContentFile(temp_image.read()) 
    dup_file.name = temp_image.name 
    new_player.profile_image = dup_file 
    new_player.save() 
0

你的代碼是一個有點混亂給我。據我瞭解,你是從profile_image2拍攝的圖像,並將其分配到profile_image字段?如果這是你想那麼這將是一個可能的答案:

image = form['profile_image2'] 
photo = PlayerForm(profile_image=image) 
photo.save() 

[這裏初學者所以有可能是輕微的錯誤,但是這是我將如何去解決這個問題,如果我在做什麼你在做]

相關問題