diff --git a/django_lostplaces/lostplaces/forms.py b/django_lostplaces/lostplaces/forms.py index 9629ff7..4a590e1 100644 --- a/django_lostplaces/lostplaces/forms.py +++ b/django_lostplaces/lostplaces/forms.py @@ -48,6 +48,14 @@ class ExplorerUserChangeForm(UserChangeForm): self.fields['username'].required = False self.fields['username'].help_text = None 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 Meta: diff --git a/django_lostplaces/lostplaces/views/explorer_views.py b/django_lostplaces/lostplaces/views/explorer_views.py index 6773f07..ccc10ff 100644 --- a/django_lostplaces/lostplaces/views/explorer_views.py +++ b/django_lostplaces/lostplaces/views/explorer_views.py @@ -60,7 +60,6 @@ class ExplorerProfileUpdateView(IsAuthenticatedMixin, View): explorer_change_form = ExplorerChangeForm(request.POST, instance=request.user.explorer) if explorer_change_form.is_valid() and explorer_user_change_form.is_valid(): - print(explorer_user_change_form) explorer_user_change_form.save() explorer_change_form.save()