title: Clean django user.username
body: <p>I have User form in which there is a username field. The fields in the form are initialized from the data in the db.</p>
  
  <pre><code>class PersonEditForm(forms.ModelForm):
  
      username = forms.RegexField(label=_("Username"), max_length=30, regex=r'^[\w.@+-]+$',
      help_text = _("Required. 30 characters or fewer. Letters, digits and @/./+/-/_ only."),
      error_messages = {'invalid': _("This value may contain only letters, numbers and @/./+/-/_ characters.")})
  
  
  class Meta:
      model = User
  </code></pre>
  
  <p>view.py</p>
  
  <pre><code>@login_required
  def edit(request, template_name):
  
      if request.user.is_authenticated():
          if request.method == 'POST':
              form = PersonEditForm(request.POST)
              if form.is_valid():
                  form.save(instance = request.POST, user = request.user)
                  return HttpResponseRedirect(reverse('/success/'))
  
          else:
              user = User.objects.get(username = request.user)
              form = PersonEditForm(instance = user, initial = {'username': request.user.username})
  
              return render_to_response(template_name, {"form": form },
                                context_instance = RequestContext(request))
  </code></pre>
  
  <p>The logged in user can edit the username. The problem  is while writing the <strong>clean_username</strong> method I would require the request.user,  to check:</p>
  
  <ol>
  <li>if username == request.user.username #return true</li>
  <li><p>elif username != request.user.username</p>
  
  <p>a) User.objects.get(username = username) #if returns something then raise forms.ValidationError(_("Username already taken."))</p>
  
  <p>b) else user.username = username </p></li>
  </ol>
  
  <p>How can I achieve this?</p>