Source

django-committees / committees / models.py

from django.db import models


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)

    class Meta:
        ordering = ('last_name', 'first_name')
    
    def __unicode__(self):
        return '%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')
    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', 'contact__last_name', 'contact__first_name',)

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