views:

125

answers:

1

Hello everyone,

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?

+2  A: 

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
Baresi
That's a pretty cool idea. Thank you! My other idea was to make the upload field optional upon editing and display the existing image with a delete button.
SapphireSun