title: Django user registration where username becomes "firstname.lastname"
body: <p>I want to make a registration page for my django application in order to 'request' access. In other words they submit the form and it creates the user and user.is_active = False. Then as admin I can approve their access. </p>
  
  <p>However I do not want them to be able to put in their username. Instead i want their username to be firstname.lastname. In the unlikely case of the same name people trying to sign up (app is for small number of people) - then a number will need adding on the end.</p>
  
  <p>I do this at the moment using a signup view:</p>
  
  <pre><code>def signup(request):
      if request.method == 'POST':
          form = SignUpForm(request.POST)
  
          if form.is_valid():
              form.save()
  
              first_name = form.cleaned_data.get('first_name')
              last_name = form.cleaned_data.get('last_name')
              raw_password = form.cleaned_data.get('password1')
              username = form.cleaned_data.get('username')
  
              user = authenticate(username=username, password=raw_password)
  
              user.is_active = False
              user.save()
              return render(request, 'registration/signedup.html', {'user': user})
          else:
              return render(request, 'registration/signup.html', {'form': form, 'invalid': 'Please try again.'})
      else:
          form = SignUpForm()
          return render(request, 'registration/signup.html', {'form': form})
  </code></pre>
  
  <p>and a signup form:</p>
  
  <pre><code>class SignUpForm(UserCreationForm):
      first_name = forms.CharField(max_length=30, required=False, help_text='Optional.')
      last_name = forms.CharField(max_length=30, required=False, help_text='Optional.')
      email = forms.EmailField(max_length=254, help_text='Required. Inform a valid email address.')
  
      class Meta:
          model = User
          fields = ('username', 'first_name', 'last_name', 'email', 'password1', 'password2', )
  </code></pre>
  
  <p>and this as the html for my signup page:</p>
  
  <pre><code>&lt;form method="post"  autocomplete="off"&gt;
    {% csrf_token %}
  
  
     &lt;table class='login' width='400'&gt;
     {% for field in form %}
  
     &lt;tr&gt;
       &lt;td width='200' class='loginrow'&gt;{{ field.label_tag }}&lt;/td&gt;
       &lt;td width='180' class='loginrow'&gt;{{ field }}&lt;/td&gt;
         {% for error in field.errors %}
        &lt;p style="color: red"&gt;{{ error }}&lt;/p&gt;
         {% endfor %}
     &lt;/tr&gt;
     {% endfor %}
  &lt;/table&gt;
  
   &lt;button type="submit"&gt;Sign up&lt;/button&gt;
  
  &lt;/form&gt;
  </code></pre>
  
  <p>I have tried to remove username from my form field, and then create username variable as firs_name+'.'+last_name in my view by the user = authenticate() returns none.</p>
  
  <p>Is there a way I can automatically produce a username without the user submitting one? - I was also thinking of using javascript function in the html page, and a hidden 'username' input tag which concats the names, but I can't get this to work either.</p>
  
  <p>Thanks</p>