title: How can I make a field in my Django app random
body: <p>I am working on a Django project and I want to make a field to always be randomly generated so they are unique in the database but I don't seem to get how to do so. I tried the following :</p>
  <pre class="lang-py prettyprint-override"><code>from django.db import models
   
   
    # Random character generation for
    # the unique short  URLs
   
    import string, random
   
    def random_url(n):
       return ''.join(random.choice(string.ascii_letters) for x in range(n))
  
   #print(random_id(6)) #testing the function
  
   #Class for the URL
  
   class ShortURL(models.Model):
         original_url = models.CharField(max_length=200)
         short_url = models.CharField(max_length=100, primary_key=True, default=random_url(6))
         timestamp = models.DateTimeField(auto_now=True)
  
  
  </code></pre>
  <p>In my admin view. All the &quot;URL&quot; have the same random code which I don't want. E.g <code>ABYpsB</code></p>
  <p>Please help needed</p>