django-members / members / models.py

import datetime

from django.db import models
from django.core.urlresolvers import reverse

from crm.models import Contact


ORDER_CHOICES = [(x, x) for x in range(-10, 11)]


class Membership(models.Model):
    type = models.ForeignKey('MembershipType', related_name='memberships')
    status = models.ForeignKey('MembershipStatus', related_name='memberships')
    contact = models.ForeignKey(Contact, related_name='memberships')
    
    class Meta:
        unique_together = ('contact', 'type')
        permissions = (
            ("can_print_membership_list", "Can print membership list"),
            ("can_export_membership_list", "Can export membership list"),
        )
    
    def __unicode__(self):
        return "%s membership: %s" % (self.type, self.contact)


class MembershipType(models.Model):
    name = models.CharField(max_length=255, unique=True)
    slug = models.SlugField(max_length=255, unique=True)
    minimum_dues = models.DecimalField(max_digits=10, decimal_places=2)
    description = models.TextField()
    order = models.SmallIntegerField(
        null=True,
        blank=True,
        choices=ORDER_CHOICES,
    )
    
    def __unicode__(self):
        return self.name


class MembershipStatus(models.Model):
    name = models.CharField(max_length=255, unique=True)
    slug = models.SlugField(max_length=255, unique=True)
    is_current_member = models.BooleanField(default=True)
    order = models.SmallIntegerField(choices=ORDER_CHOICES)
    
    class Meta:
        verbose_name_plural = 'Membership statuses'
    
    def __unicode__(self):
        return self.name


class MembershipComparison(models.Model):
    file = models.FileField(
        upload_to='membership-comparison/',
        help_text="Comma-separated Values (CSV) files only.  Must be sorted last name, first name."
    )
    date_uploaded = models.DateTimeField(default=datetime.datetime.now)
    
    class Meta:
        permissions = (
            ("can_compare_membership_list", "Can compare membership list"),
        )
    
    def __unicode__(self):
        return self.file.name
    
    def get_absolute_url(self):
        return reverse('compare_membership_list', args=(self.pk,))
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.