Source

django-committees / committees / models.py

from django.db import models
from django.contrib.localflavor.us.models import PhoneNumberField

class Profile(models.Model):
    first_name = models.CharField(max_length=50)
    last_name = models.CharField(max_length=50)
    slug = models.SlugField(unique=True)
    email = models.EmailField(blank=True)
    description = models.TextField(blank=True)
    photo = models.ImageField(blank=True, upload_to='profile-photo')
    phone = PhoneNumberField(blank=True)
    
    class Meta:
        ordering = ('last_name', 'first_name')
    
    def __unicode__(self):
        return u'%s %s' % (self.first_name, self.last_name,)


class CommitteeType(models.Model):
    name = models.CharField(max_length=255)
    slug = models.SlugField(max_length=255, unique=True)
    order = models.SmallIntegerField(
        null=True,
        blank=True,
        choices=[(x, x) for x in range(-10, 11)],
    )

    class Meta:
        ordering = ('order',)

    def __unicode__(self):
        return self.name


class Committee(models.Model):
    type = models.ForeignKey(CommitteeType, related_name='committees',
                             null=True, blank=True)
    name = models.CharField(max_length=255)
    slug = models.SlugField(max_length=255, unique=True)
    description = models.TextField(blank=True)

    class Meta:
        ordering = ('type__order', 'name')

    def __unicode__(self):
        return self.name


class CommitteeMember(models.Model):
    committee = models.ForeignKey(Committee, related_name='members')
    profile = models.ForeignKey(Profile, related_name='committee_members')
    position = models.CharField(max_length=100, blank=True)
    order = models.SmallIntegerField(
        null=True,
        blank=True,
        choices=[(x, x) for x in range(-10, 11)],
    )

    class Meta:
        ordering = ('order', 'profile__last_name', 'profile__first_name',)

    def __unicode__(self):
        position = u''
        if self.position:
            position = u" (%s)" % self.position
        return u"%s%s" % (self.profile, position)