Created
May 16, 2012 20:46
-
-
Save readevalprint/2713810 to your computer and use it in GitHub Desktop.
EmailAddress class
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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', '') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Define this after UserProfile or import it if possible and 99% sure is null=False by default