Cleaned_data returns old value if submitted field is empty

I'm trying to validate an image upload form. I want to check if the submitted field is empty or not, but when it is, cleaned_data returns the currently stored value.

class UploadProfilePicForm(ModelForm):
    class Meta:
        model = User
        fields = ( "profile_pic", )
        
    def clean_profile_pic(self):
        # if not self.cleaned_data.get("profile_pic"):
            # self._update_errors(ValidationError({ "profile_pic": "No image selected." }))

        # The following returns the submitted filename when a file is selected,
        # but the currently stored filepath/filename when no file is selected:
        self._update_errors(ValidationError({ "profile_pic": self.cleaned_data.get("profile_pic") }))
Вернуться на верх