开发者

Binding Files to Forms in Django

I'm trying to create a form where users can save their progress. I have successfully managed to upload files when they are saved, but for some reason t开发者_如何学JAVAhe following code leaves the file that was uploaded unbound from the form and thus making the user reupload the file:

class ImageForm(forms.ModelForm):
  class Meta:
    model = MyImage

imageform = ImageForm(instance=a_MyImage_instance)

I suppose I could go some manual getting and setting a la the documentation, but this behavior seems a bit odd to me. Can someone clarify this?


You could use the widget from admin to see which file is currently uploaded.

Like:

from django.contrib.auth.widgets import AdminFileWidget
class ImageForm(forms.ModelForm):
    nameofimagefield = forms.ImageField(widget=AdminFileWidget)
    class Meta:
        model = MyImage
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜