class Meta:
    model = get_user_model()
fields = ['username', 'first_name', 'last_name', 'email']

def clean_username(self):
    username = self.cleaned_data['username']
if self.instance.username == username:
    return username
try:
    User._default_manager.get(username=username)
except User.DoesNotExist:
    return username
raise forms.ValidationError(self.error_messages['duplicate_username'], code
    ='duplicate_username')
How to override django 'unique' error message for username in custom UserChangeForm