0

I'm currently using:

  1. Python 3.3
  2. Django 1.6.5
  3. django-imagekit 3.2.1
  4. django-guardian (I don't think it's related, I can confirm the row-level permissions are correct on the Profile model)

I can't seem to change the profile image through a ModelForm. The ModelForm seems to update all the other fields attached to the model when submitted through an UpdateView (goes to success_url). I've tried using a plain ImageField and using a form-ProcessedImageField and that didn't work either. Strangely enough, I can in fact "delete" the image using the UpdateView (meaning the reference to the image is removed, it remains on the disk). Also, I can freely change the image in the Admin pages and it correctly generates the thumbnail too.

Not sure what else to try or what's going on here. Help would be greatly appreciated.

Model:

class Profile(models.Model):
    ...
    avatar = ProcessedImageField(
        upload_to=get_upload_filepath,
        processors=[ResizeToFill(500, 500)],
        format='JPEG',
        blank=True,
        default='img/200x200.gif'
    )
    avatar_thumbnail = ImageSpecField(
        source='avatar',
        processors=[ResizeToFill(200,200)],
        format='JPEG',
        options = {
            'quality': 100
        }
    )
    ... some more fields

Helper function:

def get_upload_filepath(instance, filename):
    return '/'.join(['img', instance.user.username, 'avatar.jpg'])

ModelForm:

class ProfileForm(ModelForm):
    ... overridden widgets on some fields
    class Meta:
        model = Profile
        fields = ('first_name', 'last_name', 'birth_date', 'phone_number', 'avatar')

Edit:

form.cleaned_data['avatar'] is None

self.request.FILES is MultiValueDict: {}

mpalen
  • 1
  • 1
  • Do you use multipart/form-data enctype ? http://stackoverflow.com/questions/12260595/django-enctype-multipart-form-data-not-setting-post-data – Andrew_Lvov Jun 30 '14 at 23:55
  • The ModelForm generates this input type: Appears to be the same input type as what I see in the Admin page. – mpalen Jul 01 '14 at 00:01
  • Scratch that. You're right. Was missing the enctype on the form. Muchas gracias! – mpalen Jul 01 '14 at 00:22

0 Answers0