bgneal@1: from django.db import models bgneal@1: from django.contrib.localflavor.us.models import USStateField bgneal@1: from django.contrib.localflavor.us.models import PhoneNumberField bgneal@1: bgneal@1: from mysite.photologue.models import Photo bgneal@1: import datetime bgneal@1: import random bgneal@1: import string bgneal@1: bgneal@1: ####################################################################### bgneal@1: bgneal@1: class SiteConfig(models.Model): bgneal@1: band_name = models.CharField(max_length = 50) bgneal@1: url = models.URLField(verify_exists = False, max_length = 200) bgneal@1: contact_email = models.EmailField() bgneal@1: ordering_info = models.TextField(help_text = 'Enter instructions on how to order merchandise here') bgneal@1: intro_text = models.TextField(help_text = 'This text appears on the home page.') bgneal@1: intro_photo = models.ForeignKey(Photo) bgneal@1: bgneal@1: def __unicode__(self): bgneal@1: return self.band_name bgneal@1: bgneal@1: class Meta: bgneal@1: verbose_name = "Site Configuration" bgneal@1: verbose_name_plural = "Site Configuration" bgneal@1: bgneal@1: ####################################################################### bgneal@1: bgneal@1: class Member(models.Model): bgneal@1: name = models.CharField(max_length = 50, db_index = True) bgneal@1: nickname = models.CharField(max_length = 50, blank = True) bgneal@1: instrument = models.CharField(max_length = 255) bgneal@1: bio = models.TextField(blank = True) bgneal@1: photo = models.FileField(upload_to = 'images/bio/', blank = True) bgneal@1: order = models.SmallIntegerField(help_text = '''Controls order of display on the bio page, lower numbers displayed bgneal@1: first''') bgneal@1: is_active = models.BooleanField(db_index = True) bgneal@1: start_date = models.DateField() bgneal@1: end_date = models.DateField(blank = True, help_text = 'Only used if the member is not active', bgneal@1: default = datetime.date(1985, 1, 1)) bgneal@1: email = models.EmailField() bgneal@1: bgneal@1: def __unicode__(self): bgneal@1: return self.name bgneal@1: bgneal@1: class Meta: bgneal@1: ordering = ('-is_active', 'name') bgneal@1: bgneal@1: ####################################################################### bgneal@1: bgneal@1: class Gear(models.Model): bgneal@1: member = models.ForeignKey(Member) bgneal@1: item = models.CharField(max_length = 255) bgneal@1: bgneal@1: def __unicode__(self): bgneal@1: return self.item bgneal@1: bgneal@1: class Meta: bgneal@1: verbose_name_plural = 'Gear List' bgneal@1: bgneal@1: ####################################################################### bgneal@1: bgneal@1: class State(models.Model): bgneal@1: name = models.CharField(max_length = 16) bgneal@1: abbrev = USStateField() bgneal@1: bgneal@1: class Meta: bgneal@1: ordering = ('name', ) bgneal@1: bgneal@1: def __unicode__(self): bgneal@1: return self.name bgneal@1: bgneal@1: ####################################################################### bgneal@1: bgneal@1: class City(models.Model): bgneal@1: name = models.CharField(max_length = 50) bgneal@1: state = models.ForeignKey(State, null = True, blank = True) bgneal@1: bgneal@1: class Meta: bgneal@1: verbose_name_plural = 'Cities' bgneal@1: ordering = ('name', ) bgneal@1: bgneal@1: def __unicode__(self): bgneal@1: if self.state: bgneal@1: return self.name + u', ' + self.state.abbrev bgneal@1: return self.name bgneal@1: bgneal@1: ####################################################################### bgneal@1: bgneal@1: class Venue(models.Model): bgneal@1: name = models.CharField(max_length = 50, db_index = True) bgneal@1: url = models.URLField(verify_exists = False, blank = True) bgneal@1: address = models.CharField(max_length = 255, blank = True) bgneal@1: phone = PhoneNumberField(help_text = "Format: XXX-XXX-XXXX", blank = True) bgneal@1: city = models.ForeignKey(City) bgneal@1: bgneal@1: class Meta: bgneal@1: ordering = ('name', ) bgneal@1: bgneal@1: def __unicode__(self): bgneal@1: return self.name bgneal@1: bgneal@1: ####################################################################### bgneal@1: bgneal@1: class Band(models.Model): bgneal@1: name = models.CharField(max_length = 64) bgneal@1: url = models.URLField(verify_exists = False, blank = True) bgneal@1: bgneal@1: class Meta: bgneal@1: ordering = ('name', ) bgneal@1: bgneal@1: def __unicode__(self): bgneal@1: return self.name bgneal@1: bgneal@1: ####################################################################### bgneal@1: bgneal@1: class Gig(models.Model): bgneal@1: title = models.CharField(max_length = 50, blank = True, help_text = "Optional; e.g. Some Festival") bgneal@1: url = models.URLField(verify_exists = False, blank = True, help_text = "Optional; e.g. Some Festival's Website") bgneal@1: date = models.DateField(db_index = True) bgneal@1: time = models.TimeField(null = True, blank = True) bgneal@1: venue = models.ForeignKey(Venue, null = True, blank = True) bgneal@1: notes = models.TextField(blank = True) bgneal@1: bands = models.ManyToManyField(Band, blank = True) bgneal@1: flyer = models.ForeignKey(Photo, null = True, blank = True) bgneal@1: bgneal@1: def __unicode__(self): bgneal@1: if self.title: bgneal@1: return u'%s %s %s' % (self.date.strftime('%m/%d/%Y'), self.title, self.venue.name) bgneal@1: elif self.venue: bgneal@1: return u'%s %s' % (self.date.strftime('%m/%d/%Y'), self.venue.name) bgneal@1: else: bgneal@1: return u'' + self.date.strftime('%m/%d/%Y') bgneal@1: bgneal@1: class Meta: bgneal@1: ordering = ('-date', 'time') bgneal@1: bgneal@1: ####################################################################### bgneal@1: bgneal@1: class News(models.Model): bgneal@1: title = models.CharField(max_length = 64, blank = True) bgneal@1: date = models.DateField(db_index = True) bgneal@1: author = models.CharField(max_length = 50, blank = True) bgneal@1: text = models.TextField() bgneal@1: markup_enabled = models.BooleanField(default = True, bgneal@1: help_text = 'Check this box to allow Textile style markup in the text field') bgneal@1: photo = models.FileField(upload_to = 'images/news/%Y/%m/%d/', blank = True) bgneal@1: photo_caption = models.CharField(max_length = 50, blank = True) bgneal@1: bgneal@1: def __unicode__(self): bgneal@1: return u'%s %s' % (self.date.strftime('%m/%d/%Y'), self.title) bgneal@1: bgneal@1: class Meta: bgneal@1: ordering = ('-date', ) bgneal@1: verbose_name_plural = "News" bgneal@1: bgneal@1: ####################################################################### bgneal@1: bgneal@1: class Article(models.Model): bgneal@1: title = models.CharField(max_length = 64) bgneal@1: date = models.DateField(db_index = True) bgneal@1: text = models.TextField() bgneal@1: markup_enabled = models.BooleanField(default = True, bgneal@1: help_text = 'Check this box to allow Textile style markup in the text field') bgneal@1: source = models.TextField(help_text = '''Enter the source/author for the article, copyright info, etc; it will appear under bgneal@1: the article.''') bgneal@1: url = models.URLField(blank = True, help_text = 'Link to original article; optional') bgneal@1: pdf = models.FileField(upload_to = 'pdf/articles/%Y/%m/%d/', blank = True, bgneal@1: help_text = '''If you want to make the original article available as a PDF download, you may upload it bgneal@1: here.''') bgneal@1: bgneal@1: def __unicode__(self): bgneal@1: return self.title bgneal@1: bgneal@1: class Meta: bgneal@1: ordering = ('date', ) bgneal@1: bgneal@1: ####################################################################### bgneal@1: bgneal@1: class Mp3_Set(models.Model): bgneal@1: date = models.DateField(auto_now_add = True, editable = False) bgneal@1: title = models.CharField(max_length = 64) bgneal@1: text = models.TextField() bgneal@1: bgneal@1: def __unicode__(self): bgneal@1: return self.title bgneal@1: bgneal@1: class Meta: bgneal@1: ordering = ('date', ) bgneal@1: verbose_name = "MP3 Set" bgneal@1: bgneal@1: ####################################################################### bgneal@1: bgneal@1: class Mp3(models.Model): bgneal@1: mp3_set = models.ForeignKey(Mp3_Set) bgneal@1: title = models.CharField(max_length = 64) bgneal@1: desc = models.CharField(max_length = 128, blank = True) bgneal@1: file = models.FileField(upload_to = 'mp3s/%Y/%m/%d/') bgneal@1: slug = models.SlugField(unique = True) bgneal@1: bgneal@1: def __unicode__(self): bgneal@1: return self.title bgneal@1: bgneal@1: class Meta: bgneal@1: ordering = ('title', ) bgneal@1: verbose_name = "MP3" bgneal@1: bgneal@1: ####################################################################### bgneal@1: bgneal@1: class Video_Set(models.Model): bgneal@1: date = models.DateField(auto_now_add = True, editable = False) bgneal@1: title = models.CharField(max_length = 64) bgneal@1: text = models.TextField() bgneal@1: bgneal@1: def __unicode__(self): bgneal@1: return self.title bgneal@1: bgneal@1: class Meta: bgneal@1: ordering = ('date', ) bgneal@1: verbose_name = "Video Set" bgneal@1: bgneal@1: ####################################################################### bgneal@1: bgneal@1: class Video(models.Model): bgneal@1: video_set = models.ForeignKey(Video_Set) bgneal@1: title = models.CharField(max_length = 64) bgneal@1: embed_code = models.CharField(max_length = 1024) bgneal@1: bgneal@1: def __unicode__(self): bgneal@1: return self.title bgneal@1: bgneal@1: class Meta: bgneal@1: ordering = ('title', ) bgneal@1: bgneal@1: ####################################################################### bgneal@1: bgneal@1: class Record_Label(models.Model): bgneal@1: name = models.CharField(max_length = 64) bgneal@1: url = models.URLField(verify_exists = False, max_length = 200) bgneal@1: bgneal@1: def __unicode__(self): bgneal@1: return self.name bgneal@1: bgneal@1: class Meta: bgneal@1: verbose_name = 'Record Label' bgneal@1: bgneal@1: ####################################################################### bgneal@1: bgneal@1: class Album(models.Model): bgneal@1: title = models.CharField(max_length = 64) bgneal@1: photo = models.ForeignKey(Photo) bgneal@1: desc = models.TextField(blank = True) bgneal@1: bgneal@1: def __unicode__(self): bgneal@1: return self.title bgneal@1: bgneal@1: class Meta: bgneal@1: pass bgneal@1: bgneal@1: ####################################################################### bgneal@1: bgneal@1: class Album_Track(models.Model): bgneal@1: album = models.ForeignKey(Album) bgneal@1: track_number = models.SmallIntegerField() bgneal@1: track_name = models.CharField(max_length = 64) bgneal@1: bgneal@1: def __unicode__(self): bgneal@1: return self.track_name bgneal@1: bgneal@1: class Meta: bgneal@1: verbose_name = 'Album Track' bgneal@1: ordering = ('album', 'track_number', ) bgneal@1: bgneal@1: ####################################################################### bgneal@1: bgneal@1: class Label_Release(models.Model): bgneal@1: record_label = models.ForeignKey(Record_Label) bgneal@1: album = models.ForeignKey(Album) bgneal@1: catalog_number = models.CharField(max_length = 32) bgneal@1: release_date = models.DateField() bgneal@1: bgneal@1: def __unicode__(self): bgneal@1: return u'%s %s %s' % (self.record_label.name, self.album.title, self.catalog_number) bgneal@1: bgneal@1: class Meta: bgneal@1: verbose_name = 'Label Release' bgneal@1: bgneal@1: ####################################################################### bgneal@1: bgneal@1: class Album_Merchant(models.Model): bgneal@1: album = models.ForeignKey(Album) bgneal@1: name = models.CharField(max_length = 64) bgneal@1: url = models.URLField(verify_exists = False, max_length = 200) bgneal@1: bgneal@1: def __unicode__(self): bgneal@1: return u'%s (%s)' % (self.name, self.album.title) bgneal@1: bgneal@1: class Meta: bgneal@1: verbose_name = 'Album Merchant' bgneal@1: ordering = ('name', ) bgneal@1: bgneal@1: ####################################################################### bgneal@1: bgneal@1: class Merchandise(models.Model): bgneal@1: name = models.CharField(max_length = 64) bgneal@1: desc = models.TextField() bgneal@1: price = models.DecimalField(max_digits = 5, decimal_places = 2) bgneal@1: in_stock = models.BooleanField() bgneal@1: photo = models.ForeignKey(Photo) bgneal@1: bgneal@1: def __unicode__(self): bgneal@1: return self.name bgneal@1: bgneal@1: class Meta: bgneal@1: verbose_name_plural = "Merchandise" bgneal@1: bgneal@1: ####################################################################### bgneal@1: bgneal@1: class Fan(models.Model): bgneal@1: statusCodes = (('P', 'Pending'), ('A', 'Active'), ('L', 'Leaving')) bgneal@1: keyLength = 16 bgneal@1: bgneal@1: name = models.CharField(max_length = 32, blank = True) bgneal@1: email = models.EmailField(db_index = True) bgneal@1: location = models.CharField(max_length = 64, blank = True) bgneal@1: status = models.CharField(max_length = 1, choices = statusCodes, default = 'A', bgneal@1: editable = False, db_index = True) bgneal@1: key = models.CharField(max_length = keyLength, editable = False, blank = True, db_index = True) bgneal@1: status_date = models.DateField(default = datetime.date.today, editable = False, db_index = True) bgneal@1: bgneal@1: def __unicode__(self): bgneal@1: if self.name: bgneal@1: return u'%s <%s>' % (self.name, self.email) bgneal@1: return self.email bgneal@1: bgneal@1: class Meta: bgneal@1: ordering = ('name', 'email') bgneal@1: bgneal@1: def setPending(self): bgneal@1: self.status = 'P' bgneal@1: self.status_date = datetime.date.today() bgneal@1: self.genKey() bgneal@1: bgneal@1: def setActive(self): bgneal@1: self.status = 'A' bgneal@1: self.status_date = datetime.date.today() bgneal@1: bgneal@1: def setLeaving(self): bgneal@1: self.status = 'L' bgneal@1: self.status_date = datetime.date.today() bgneal@1: self.genKey() bgneal@1: bgneal@1: def isPending(self): bgneal@1: return self.status == 'P' bgneal@1: bgneal@1: def isLeaving(self): bgneal@1: return self.status == 'L' bgneal@1: bgneal@1: def isActive(self): bgneal@1: return self.status == 'A' bgneal@1: bgneal@1: def current_status(self): bgneal@1: if self.status == 'P': bgneal@1: return 'Pending' bgneal@1: elif self.status == 'L': bgneal@1: return 'Leaving' bgneal@1: elif self.status == 'A': bgneal@1: return 'Active' bgneal@1: else: bgneal@1: return 'Unknown' bgneal@1: bgneal@1: def genKey(self): bgneal@1: self.key = ''.join(random.sample(string.ascii_letters + string.digits, self.keyLength)) bgneal@1: