1π
β
The error
user
is not defined makes complete sense sinceuser
is not defined anywhere.
To resolve the problem, try to use self.instance.mnemonic
which will give the current instanceβs mnemonic so:
class UserUpdateForm(forms.ModelForm):
class Meta:
model = User
fields = ['image', 'mnemonic']
def clean(self):
super(UserUpdateForm, self).clean()
mnemonic = self.cleaned_data.get('mnemonic')
if mnemonic != self.instance.mnemonic:
self._errors['mnemonic'] = self.error_class([
'The mnemonic is wrong!'])
return self.cleaned_data
Note: Function based views are generally written in
snake_case
notPascalCase
unlike class based views, so it is better to rename it asprofile_view
fromProfileView
.
π€Sunderam Dubey
Source:stackexchange.com