Mercurial > agora-palash
diff apps/snippet/models.py @ 207:d534881629ff
Updated snippet's template and views files to fix rating code collision which prevented posting new snippets.
Updated snippet's models file so that now secret id of each snippet will be unique. It also means that the no two or more than two snippets will have same secret id.
author | Ahsan Ali Shahid <ahsan.ali.shahid@gmail.com> |
---|---|
date | Mon, 19 Aug 2013 20:30:19 +0500 |
parents | 1f1e867cb37f |
children |
line wrap: on
line diff
--- a/apps/snippet/models.py Fri Jul 19 22:54:18 2013 +0500 +++ b/apps/snippet/models.py Mon Aug 19 20:30:19 2013 +0500 @@ -12,7 +12,10 @@ t = 'abcdefghijkmnopqrstuvwwxyzABCDEFGHIJKLOMNOPQRSTUVWXYZ1234567890' def generate_secret_id(length=4): - return ''.join([random.choice(t) for i in range(length)]) + unique_id = ''.join([random.choice(t) for i in range(length)]) + while Snippet.objects.filter(secret_id = unique_id ).count()!= 0: + unique_id = ''.join([random.choice(t) for i in range(length)]) + return unique_id class SnippetManager(models.Manager): def public(self):