view mysite/band/models.py @ 20:7aa63299adf6

Adding a work around for IE path problem in the .css file, as per http://groups.google.com/group/fancybox/browse_frm/thread/8530478044b9f586
author Brian Neal <bgneal@gmail.com>
date Wed, 08 Sep 2010 23:15:57 +0000
parents dac690ab98b2
children 25e00d1b99bf
line wrap: on
line source
from django.db import models
from django.contrib.localflavor.us.models import USStateField
from django.contrib.localflavor.us.models import PhoneNumberField

from mysite.photologue.models import Photo
import datetime 
import random
import string

#######################################################################

class SiteConfig(models.Model):
   band_name = models.CharField(max_length = 50)
   url = models.URLField(verify_exists = False, max_length = 200)
   contact_email = models.EmailField()
   ordering_info = models.TextField(help_text = 'Enter instructions on how to order merchandise here')
   intro_text = models.TextField(help_text = 'This text appears on the home page.')
   intro_photo = models.ForeignKey(Photo)

   def __unicode__(self):
      return self.band_name

   class Meta:
      verbose_name = "Site Configuration"
      verbose_name_plural = "Site Configuration"

#######################################################################

class Member(models.Model):
   name = models.CharField(max_length = 50, db_index = True)
   nickname = models.CharField(max_length = 50, blank = True)
   instrument = models.CharField(max_length = 255)
   bio = models.TextField(blank = True)
   photo = models.FileField(upload_to = 'images/bio/', blank = True)
   order = models.SmallIntegerField(help_text = '''Controls order of display on the bio page, lower numbers displayed
         first''')
   is_active = models.BooleanField(db_index = True)
   start_date = models.DateField()
   end_date = models.DateField(blank = True, help_text = 'Only used if the member is not active',
         default = datetime.date(1985, 1, 1))
   email = models.EmailField()

   def __unicode__(self):
      return self.name

   class Meta:
      ordering = ('-is_active', 'name')

#######################################################################

class Gear(models.Model):
   member = models.ForeignKey(Member)
   item = models.CharField(max_length = 255)

   def __unicode__(self):
      return self.item

   class Meta:
      verbose_name_plural = 'Gear List'

#######################################################################

class Country(models.Model):
    name = models.CharField(max_length=64)

    class Meta:
        ordering = ('name', )
        verbose_name_plural = 'Countries'

    def __unicode__(self):
        return self.name

#######################################################################

class State(models.Model):
   name = models.CharField(max_length = 16)
   abbrev = USStateField()

   class Meta:
      ordering = ('name', )

   def __unicode__(self):
      return self.name

#######################################################################

class City(models.Model):
   name = models.CharField(max_length = 50)
   state = models.ForeignKey(State, null = True, blank = True)
   country = models.ForeignKey(Country, null=True, blank=True)

   class Meta:
      verbose_name_plural = 'Cities'
      ordering = ('name', )

   def __unicode__(self):
      if self.state:
         return self.name + u', ' + self.state.abbrev
      return self.name

#######################################################################

class Venue(models.Model):
   name = models.CharField(max_length = 50, db_index = True)
   url = models.URLField(verify_exists = False, blank = True)
   address = models.CharField(max_length = 255, blank = True)
   phone = PhoneNumberField(help_text = "Format: XXX-XXX-XXXX", blank = True)
   city = models.ForeignKey(City)

   class Meta:
      ordering = ('name', )

   def __unicode__(self):
      return self.name

#######################################################################

class Band(models.Model):
   name = models.CharField(max_length = 64)
   url = models.URLField(verify_exists = False, blank = True)

   class Meta:
      ordering = ('name', )

   def __unicode__(self):
      return self.name

#######################################################################

class Gig(models.Model):
   title = models.CharField(max_length = 50, blank = True, help_text = "Optional; e.g. Some Festival")
   url = models.URLField(verify_exists = False, blank = True, help_text = "Optional; e.g. Some Festival's Website")
   date = models.DateField(db_index = True)
   time = models.TimeField(null = True, blank = True)
   venue = models.ForeignKey(Venue, null = True, blank = True)
   notes = models.TextField(blank = True)
   bands = models.ManyToManyField(Band, blank = True)
   flyer = models.ForeignKey(Photo, null = True, blank = True)

   def __unicode__(self):
      if self.title:
         return u'%s %s %s' % (self.date.strftime('%m/%d/%Y'), self.title, self.venue.name)
      elif self.venue:
         return u'%s %s' % (self.date.strftime('%m/%d/%Y'), self.venue.name)
      else:
         return u'' + self.date.strftime('%m/%d/%Y')

   class Meta:
      ordering = ('-date', 'time')

#######################################################################

class News(models.Model):
   title = models.CharField(max_length = 64, blank = True)
   date = models.DateField(db_index = True)
   author = models.CharField(max_length = 50, blank = True)
   text = models.TextField()
   markup_enabled = models.BooleanField(default = True,
         help_text = 'Check this box to allow Textile style markup in the text field')
   photo = models.FileField(upload_to = 'images/news/%Y/%m/%d/', blank = True)
   photo_caption = models.CharField(max_length = 50, blank = True)

   def __unicode__(self):
      return u'%s %s' % (self.date.strftime('%m/%d/%Y'), self.title)

   class Meta:
      ordering = ('-date', )
      verbose_name_plural = "News"

#######################################################################

class Article(models.Model):
   title = models.CharField(max_length = 64)
   date = models.DateField(db_index = True)
   text = models.TextField()
   markup_enabled = models.BooleanField(default = True,
         help_text = 'Check this box to allow Textile style markup in the text field')
   source = models.TextField(help_text = '''Enter the source/author for the article, copyright info, etc; it will appear under
            the article.''')
   url = models.URLField(blank = True, help_text = 'Link to original article; optional')
   pdf = models.FileField(upload_to = 'pdf/articles/%Y/%m/%d/', blank = True, 
            help_text = '''If you want to make the original article available as a PDF download, you may upload it
            here.''')

   def __unicode__(self):
      return self.title

   class Meta:
      ordering = ('date', )

#######################################################################

class Mp3_Set(models.Model):
   date = models.DateField(auto_now_add = True, editable = False)
   title = models.CharField(max_length = 64)
   text = models.TextField()

   def __unicode__(self):
      return self.title

   class Meta:
      ordering = ('date', )
      verbose_name = "MP3 Set"

#######################################################################

class Mp3(models.Model):
   mp3_set = models.ForeignKey(Mp3_Set)
   title = models.CharField(max_length = 64)
   desc = models.CharField(max_length = 128, blank = True)
   file = models.FileField(upload_to = 'mp3s/%Y/%m/%d/')
   slug = models.SlugField(unique = True)

   def __unicode__(self):
      return self.title

   class Meta:
      ordering = ('title', )
      verbose_name = "MP3"

#######################################################################

class Video_Set(models.Model):
   date = models.DateField(blank=True)
   title = models.CharField(max_length = 64)
   text = models.TextField()

   def __unicode__(self):
      return self.title

   class Meta:
      ordering = ('date', )
      verbose_name = "Video Set"

   def save(self, *args, **kwargs):
      if not self.id:
          self.date = datetime.date.today()

      super(Video_Set, self).save(*args, **kwargs)

#######################################################################

class Video(models.Model):
   video_set = models.ForeignKey(Video_Set)
   title = models.CharField(max_length = 64)
   embed_code = models.CharField(max_length = 1024)

   def __unicode__(self):
      return self.title

   class Meta:
      ordering = ('title', )

#######################################################################

class Record_Label(models.Model):
   name = models.CharField(max_length = 64)
   url = models.URLField(verify_exists = False, max_length = 200)

   def __unicode__(self):
      return self.name

   class Meta:
      verbose_name = 'Record Label'

#######################################################################

class Album(models.Model):
   title = models.CharField(max_length = 64)
   photo = models.ForeignKey(Photo)
   desc = models.TextField(blank = True)

   def __unicode__(self):
      return self.title

   class Meta:
      pass

#######################################################################

class Album_Track(models.Model):
   album = models.ForeignKey(Album)
   track_number = models.SmallIntegerField()
   track_name = models.CharField(max_length = 64)

   def __unicode__(self):
      return self.track_name

   class Meta:
      verbose_name = 'Album Track'
      ordering = ('album', 'track_number', )

#######################################################################

class Label_Release(models.Model):
   record_label = models.ForeignKey(Record_Label)
   album = models.ForeignKey(Album)
   catalog_number = models.CharField(max_length = 32)
   release_date = models.DateField()

   def __unicode__(self):
      return u'%s %s %s' % (self.record_label.name, self.album.title, self.catalog_number)

   class Meta:
      verbose_name = 'Label Release'

#######################################################################

class Album_Merchant(models.Model):
   album = models.ForeignKey(Album)
   name = models.CharField(max_length = 64)
   url = models.URLField(verify_exists = False, max_length = 200)

   def __unicode__(self):
      return u'%s (%s)' % (self.name, self.album.title)

   class Meta:
      verbose_name = 'Album Merchant'
      ordering = ('name', )

#######################################################################

class Merchandise(models.Model):
   name = models.CharField(max_length = 64)
   desc = models.TextField()
   price = models.DecimalField(max_digits = 5, decimal_places = 2)
   in_stock = models.BooleanField()
   photo = models.ForeignKey(Photo)

   def __unicode__(self):
      return self.name

   class Meta:
      verbose_name_plural = "Merchandise"

#######################################################################

class Fan(models.Model):
   statusCodes = (('P', 'Pending'), ('A', 'Active'), ('L', 'Leaving'))
   keyLength = 16

   name = models.CharField(max_length = 32, blank = True)
   email = models.EmailField(db_index = True)
   location = models.CharField(max_length = 64, blank = True)
   status = models.CharField(max_length = 1, choices = statusCodes, default = 'A', 
         editable = False, db_index = True)
   key = models.CharField(max_length = keyLength, editable = False, blank = True, db_index = True)
   status_date = models.DateField(default = datetime.date.today, editable = False, db_index = True)

   def __unicode__(self):
      if self.name:
         return u'%s <%s>' % (self.name, self.email)
      return self.email

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

   def setPending(self):
      self.status = 'P'
      self.status_date = datetime.date.today()
      self.genKey()

   def setActive(self):
      self.status = 'A'
      self.status_date = datetime.date.today()

   def setLeaving(self):
      self.status = 'L'
      self.status_date = datetime.date.today()
      self.genKey()

   def isPending(self):
      return self.status == 'P'

   def isLeaving(self):
      return self.status == 'L'

   def isActive(self):
      return self.status == 'A'

   def current_status(self):
      if self.status == 'P':
         return 'Pending'
      elif self.status == 'L':
         return 'Leaving'
      elif self.status == 'A':
         return 'Active'
      else:
         return 'Unknown'

   def genKey(self):
      self.key = ''.join(random.sample(string.ascii_letters + string.digits, self.keyLength))