1. Jay Baird
  2. Ochs

Source

Ochs / staff / models.py

from django.db import models
from django.contrib.auth.models import User, UserManager

SUPERUSER = 'S'
REPORTER = 'R'
EDITOR = 'E'
PHOTOGRAPHER = 'P'
FACULTY = 'F'
CONTRIBUTOR = 'C'
ROLES = (
    (SUPERUSER, 'Admin'),
    (REPORTER, 'Reporter'),
    (EDITOR, 'Editor'),
    (PHOTOGRAPHER, 'Photographer'),
    (FACULTY, 'Faculty'),
    (CONTRIBUTOR, 'Contributor')
)
NON_CONTRIBUTOR = [EDITOR, REPORTER, FACULTY, SUPERUSER]
EVERYONE = [EDITOR, REPORTER, PHOTOGRAPHER, CONTRIBUTOR, FACULTY, SUPERUSER]
PUBLISH = [EDITOR, REPORTER, FACULTY, SUPERUSER]
STAFF = [EDITOR, REPORTER, PHOTOGRAPHER, CONTRIBUTOR, FACULTY]

class Position(models.Model):
    position = models.CharField(max_length=2, choices=ROLES)

    def __unicode__(self):
        return dict(ROLES)[self.position]

    class Meta:
        ordering = ('-position',)

class Profile(User):
    hometown = models.TextField(blank=True)
    photo = models.ImageField(upload_to="staff", verbose_name="Profile Photo", blank=True)
    bio = models.TextField(blank=True)
    personal_url = models.URLField(verify_exists=False, null=True, blank=True)
    position = models.ManyToManyField(Position, help_text="Setting a user as a Contributor will lock that user to ONLY contributor status")

    def name(self):
        return '%s %s' % (self.first_name, self.last_name)

    def save(self):
        self.is_staff = True
        super(Profile, self).save()

    def has_module_perms(self, module):
        return True

    def get_absolute_url(self):
        return '/staff/%s' % (self.username)

    def __unicode__(self):
        return '%s %s (%s)' % (self.first_name, self.last_name, self.username)