title: Slugify string in Django
body: <p>I have developed a form, where the user adds his/her <code>first name</code> and <code>last name</code>.</p>
  
  <p>For the <code>username</code> (a <code>unique</code> property), I've devised the following method:</p>
  
  <p><code>FirstName</code>: harrY <code>LastName</code>: PottEr --> <code>username</code>: Harry-Potter</p>
  
  <p><code>FirstName</code>: HARRY <code>LastName</code>: POTTER --> <code>username</code>: Harry-Potter-1</p>
  
  <p><code>FirstName</code>: harrY <code>LastName</code>: PottEr --> <code>username</code>: Harry-Potter-2</p>
  
  <p>And so on..</p>
  
  <p>Here's my function definition:</p>
  
  <pre><code>def return_slug(firstname, lastname):
      u_username = firstname.title()+'-'+lastname.title()         //Step 1
      u_username = '-'.join(u_username.split())                     //Step 2
      count = User.objects.filter(username=u_username).count()    //Step 3
      if count==0:
          return (u_username)
      else:
          return (u_username+'-%s' % count)
  </code></pre>
  
  <p>I can't figure out what to do before <code>Step 3</code> for the implementation. Where should I put <code>[:len(u_username)]</code> to compare the strings?</p>
  
  <p><strong>EDIT:</strong></p>
  
  <p>This method is applied if there are multiple instances of <code>Harry-Potter</code>, by resolving the issue of adding an integer in the end. My question is: How will I check that how what was the last integer appended to <code>Harry-Potter</code>. </p>