开发者

Assign image to a form field in django.views

I am in the middle of a project and I am stuck. I have a edit profile feature where a user can edit their profile. Everytime a profile is created with an empty profile_picture field a default value is provided. But once an image is assigned to field and then deleted. The field gets blank. What I want is everytime the field becomes None I want to reassign the default image by mentioning the file path.

Heres My view where I save the model form:-

           if form.is_valid():
                form.save(commit=False)

                print(form.cleaned_data)
                if 'avatar' in form.cleaned_data:

                    if form.cleaned_data.get('avatar') is False:
                       开发者_StackOverflow中文版 form.cleaned_data['avatar'] = image

                form.save() 

I want to mention the image path in place of image. Also suggest me some better ways for doing this.


if form.is_valid(): form.save(commit=False)

            print(form.cleaned_data)
            if 'avatar' in form.cleaned_data:

                if form.cleaned_data.get('avatar') is False:
                    form.cleaned_data['avatar'] = image

            form.save() 
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜