Skip to content

Instantly share code, notes, and snippets.

@readevalprint
Created May 16, 2012 20:46
Show Gist options
  • Save readevalprint/2713810 to your computer and use it in GitHub Desktop.
Save readevalprint/2713810 to your computer and use it in GitHub Desktop.
EmailAddress class
EMAIL_TYPE_CHOICES = (
('work', 'Work'),
('home', 'Person'),
('other', 'Other'),
)
class EmailAddress(models.Model):
email = models.EmailField(db_index=True, max_length=254, unique=True)
# Allows us to remove the choices and be backwards compatible
type = models.CharField(max_length=10, choices=EMAIL_TYPE_CHOICES)
userprofile = models.ForeignKey(UserProfile)
@classmethod
def search(cls, query):
if query:
q = dict('user', query)
s = S(cls).query(or_=q)
return s
def __unicode__(self):
"""Return the email or blank"""
return getattr(self, 'email', '')
@readevalprint
Copy link
Author

Define this after UserProfile or import it if possible and 99% sure is null=False by default

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment