title: Checking if form input exists [Django]
body: <p>I have a Django form that a user enters one input into. After submitting they are taken to a URL associated with their input.</p>
  
  <p>The database contains <code>user_input</code> and <code>associated_url</code> fields.</p>
  
  <p>The <code>user_input</code> has the value <code>unique=True</code> set. When a duplicate input is entered the following displays on the website <code>This value user_input already exists in the database</code> even though I didn't set this so it. This may be feature of <code>form.is_valid()</code>?</p>
  
  <p>So it immediately recognizes duplicate values, but I am trying to set it so that if a duplicate value is entered then it will just take the user to the <code>associated_url</code> for that value.</p>
  
  <p>i.e.</p>
  
  <p>Existing database table: </p>
  
  <pre><code>user_input    associated_url
  
  hello     https://stackoverflow.com
  </code></pre>
  
  <p>If a user were to input <code>hello</code> into the form again, it would immedietly take them to <code>https://stackoverflow.com</code> instead of showing <code>This value user_input already exists in the database</code></p>
  
  <p>Code:</p>
  
  <pre><code>def Primary(request):
  
      form = Form()
  
      if request.method == 'POST':
  
          form = Form(request.POST)
  
          if form.is_valid():
  
                  ... saving to database, redirect etc.
  </code></pre>
  
  <p>I need to be able to check if the input value is a duplicate. If it is then get the <code>associated_url</code> from the same row as the duplicate <code>user_input</code> entry and  redirect the user there.</p>
  
  <p>To do this myself I attempted adding an <code>else</code> statement to the <code>form.is_valid</code> condition, but that seems like bad practice because it will attempt to redirect regardless of the error(?) and because I don't know how to get the <code>associated_url</code> associated with the input value.</p>