Mercurial > public > sg101
comparison accounts/models.py @ 623:1555b2c3c7a0
For issue #22, add a UNIQUE contraint on the pending user table's username field.
author | Brian Neal <bgneal@gmail.com> |
---|---|
date | Wed, 31 Oct 2012 20:06:01 -0500 |
parents | ee87ea74d46b |
children |
comparison
equal
deleted
inserted
replaced
622:91a6a1b5007f | 623:1555b2c3c7a0 |
---|---|
42 '''creates a new pending user and saves it to the database''' | 42 '''creates a new pending user and saves it to the database''' |
43 | 43 |
44 temp_user = User() | 44 temp_user = User() |
45 temp_user.set_password(password) | 45 temp_user.set_password(password) |
46 | 46 |
47 now = datetime.datetime.now() | 47 now = datetime.datetime.now() |
48 pending_user = self.model(None, | 48 pending_user = self.model(None, |
49 username, | 49 username, |
50 email, | 50 email, |
51 temp_user.password, | 51 temp_user.password, |
52 now, | 52 now, |
53 self._make_key()) | 53 self._make_key()) |
54 | 54 |
55 pending_user.save() | 55 pending_user.save() |
56 self.create_count += 1 | 56 self.create_count += 1 |
57 return pending_user | 57 return pending_user |
75 | 75 |
76 | 76 |
77 class PendingUser(models.Model): | 77 class PendingUser(models.Model): |
78 """model for holding users while they go through the email registration cycle""" | 78 """model for holding users while they go through the email registration cycle""" |
79 | 79 |
80 username = models.CharField(max_length=30, db_index=True) | 80 username = models.CharField(max_length=30, db_index=True, unique=True) |
81 email = models.EmailField() | 81 email = models.EmailField() |
82 password = models.CharField(max_length=128) | 82 password = models.CharField(max_length=128) |
83 date_joined = models.DateTimeField(default=datetime.datetime.now, db_index=True) | 83 date_joined = models.DateTimeField(default=datetime.datetime.now, db_index=True) |
84 key = models.CharField(max_length=20, editable=True) | 84 key = models.CharField(max_length=20) |
85 | 85 |
86 objects = PendingUserManager() | 86 objects = PendingUserManager() |
87 | 87 |
88 def __unicode__(self): | 88 def __unicode__(self): |
89 return self.username | 89 return self.username |