title: Combining queryset into single string with Django
body: <p>Say I have an extremely simple model that is just a list of words:</p>
  
  <pre><code>class WordList(models.Model):
      word = models.CharField(max_length=60)
  </code></pre>
  
  <p>After a user submits a form, I want to... </p>
  
  <ul>
  <li>Retrieve four random words</li>
  <li>Combine them into a single string</li>
  <li>Ensure a duplicate string has not been previously generated and if so, run it again</li>
  <li>Save that to the database when it's good</li>
  <li>Return the result to the user. </li>
  </ul>
  
  <p>I know how to get four random words:</p>
  
  <pre><code>WordList.objects.order_by('?')[:4]
  </code></pre>
  
  <p>I know how to make this a context and return it to a template, at which point I can do whatever with it, but I'm stumped on how I do this behind the scenes so I can do the rest of my stuff before returning it to the user. The final string should look like this:</p>
  
  <pre><code>these-are-my-words
  </code></pre>
  
  <p>Furthermore, <em>where</em> in my app do I do this? I come from PHP and there, I would have a <code>functions.php</code> file or something to perform backend stuff and keep it out of the presentation. I've found a few other posts from people stating they use a <code>functions.py</code>, but I'm not sure how to include external pages that aren't in the same folder as the existing <code>views.py</code>. If I do:</p>
  
  <pre><code>from functions import myfunc
  </code></pre>
  
  <p>It only works if <code>functions.py</code> is in the folder as wherever I am importing it from.</p>