Skip to content

Instantly share code, notes, and snippets.

@readevalprint
Created May 16, 2012 20:46

Revisions

  1. readevalprint revised this gist May 16, 2012. 1 changed file with 12 additions and 6 deletions.
    18 changes: 12 additions & 6 deletions models.py
    Original file line number Diff line number Diff line change
    @@ -1,9 +1,15 @@
    EMAIL_TYPE_CHOICES = (
    ('work', 'Work'),
    ('home', 'Person'),
    ('other', 'Other'),
    )

    class EmailAddress(models.Model):
    email = models.EmailField(db_index=True, max_length=254, unique=True)
    user = models.ForeignKey('UserProfile', null=False)

    class Meta:
    db_table = 'emails'
    # 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):
    @@ -13,5 +19,5 @@ def search(cls, query):
    return s

    def __unicode__(self):
    """Return the Email Address or return blank"""
    return getattr(self, 'email', u'')
    """Return the email or blank"""
    return getattr(self, 'email', '')
  2. @davidw93 davidw93 created this gist May 16, 2012.
    17 changes: 17 additions & 0 deletions models.py
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,17 @@
    class EmailAddress(models.Model):
    email = models.EmailField(db_index=True, max_length=254, unique=True)
    user = models.ForeignKey('UserProfile', null=False)

    class Meta:
    db_table = 'emails'

    @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 Address or return blank"""
    return getattr(self, 'email', u'')