Question

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 the 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?

Was it helpful?

Solution

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
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top