Added clean_username function to validate form.
This commit is contained in:
parent
67a6517716
commit
cc59254ba4
@ -49,6 +49,14 @@ class ExplorerUserChangeForm(UserChangeForm):
|
|||||||
self.fields['username'].help_text = None
|
self.fields['username'].help_text = None
|
||||||
self.fields['username'].widget.attrs['disabled'] = 'disabled'
|
self.fields['username'].widget.attrs['disabled'] = 'disabled'
|
||||||
|
|
||||||
|
def clean_username(self):
|
||||||
|
# As shown in the above answer.
|
||||||
|
instance = getattr(self, 'instance', None)
|
||||||
|
if instance:
|
||||||
|
return instance.username
|
||||||
|
else:
|
||||||
|
return self.cleaned_data.get('username', None)
|
||||||
|
|
||||||
class ExplorerChangeForm(forms.ModelForm):
|
class ExplorerChangeForm(forms.ModelForm):
|
||||||
class Meta:
|
class Meta:
|
||||||
model = Explorer
|
model = Explorer
|
||||||
|
@ -60,7 +60,6 @@ class ExplorerProfileUpdateView(IsAuthenticatedMixin, View):
|
|||||||
explorer_change_form = ExplorerChangeForm(request.POST, instance=request.user.explorer)
|
explorer_change_form = ExplorerChangeForm(request.POST, instance=request.user.explorer)
|
||||||
|
|
||||||
if explorer_change_form.is_valid() and explorer_user_change_form.is_valid():
|
if explorer_change_form.is_valid() and explorer_user_change_form.is_valid():
|
||||||
print(explorer_user_change_form)
|
|
||||||
explorer_user_change_form.save()
|
explorer_user_change_form.save()
|
||||||
explorer_change_form.save()
|
explorer_change_form.save()
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user