bgneal@44: """ bgneal@44: Models for the gigs application. bgneal@44: bgneal@44: """ bgneal@44: from django.db import models bgneal@90: from localflavor.us.models import USStateField bgneal@90: from localflavor.us.models import PhoneNumberField bgneal@44: bgneal@44: from photologue.models import Photo bgneal@44: bgneal@44: bgneal@44: class Country(models.Model): bgneal@44: name = models.CharField(max_length=64) bgneal@44: bgneal@44: class Meta: bgneal@44: ordering = ['name'] bgneal@44: verbose_name_plural = 'Countries' bgneal@44: bgneal@44: def __unicode__(self): bgneal@44: return self.name bgneal@44: bgneal@44: bgneal@44: class State(models.Model): bgneal@44: name = models.CharField(max_length=16) bgneal@44: abbrev = USStateField() bgneal@44: bgneal@44: class Meta: bgneal@44: ordering = ['name'] bgneal@44: bgneal@44: def __unicode__(self): bgneal@44: return self.name bgneal@44: bgneal@44: bgneal@44: class City(models.Model): bgneal@44: name = models.CharField(max_length=50) bgneal@44: state = models.ForeignKey(State, null=True, blank=True) bgneal@44: country = models.ForeignKey(Country, null=True, blank=True) bgneal@44: bgneal@44: class Meta: bgneal@44: verbose_name_plural = 'Cities' bgneal@44: ordering = ['name'] bgneal@44: bgneal@44: def __unicode__(self): bgneal@44: if self.state: bgneal@44: return u'%s, %s' % (self.name, self.state.abbrev) bgneal@90: bgneal@44: return self.name bgneal@44: bgneal@44: bgneal@44: class Venue(models.Model): bgneal@44: name = models.CharField(max_length=50) bgneal@64: url = models.URLField(blank=True) bgneal@44: address = models.CharField(max_length=255, blank=True) bgneal@44: phone = PhoneNumberField(help_text="Format: XXX-XXX-XXXX", blank=True) bgneal@44: city = models.ForeignKey(City) bgneal@44: bgneal@44: class Meta: bgneal@44: ordering = ['name'] bgneal@44: bgneal@44: def __unicode__(self): bgneal@44: return self.name bgneal@44: bgneal@44: bgneal@44: class Band(models.Model): bgneal@44: name = models.CharField(max_length=64) bgneal@64: url = models.URLField(blank=True) bgneal@44: bgneal@44: class Meta: bgneal@44: ordering = ['name'] bgneal@44: bgneal@44: def __unicode__(self): bgneal@44: return self.name bgneal@44: bgneal@44: bgneal@44: class Gig(models.Model): bgneal@44: title = models.CharField(max_length=50, blank=True, bgneal@44: help_text="Optional; e.g. Some Festival") bgneal@64: url = models.URLField(blank=True, bgneal@44: help_text="Optional; e.g. Some Festival's Website") bgneal@44: date = models.DateField(db_index=True) bgneal@44: time = models.TimeField(null=True, blank=True) bgneal@44: venue = models.ForeignKey(Venue, null=True, blank=True) bgneal@44: notes = models.TextField(blank=True) bgneal@44: bands = models.ManyToManyField(Band, blank=True) bgneal@44: flyer = models.ForeignKey(Photo, null=True, blank=True, bgneal@44: related_name='gig_flyers') bgneal@44: bgneal@44: def __unicode__(self): bgneal@44: if self.title: bgneal@44: return u'%s %s %s' % (self.date.strftime('%m/%d/%Y'), self.title, self.venue.name) bgneal@44: elif self.venue: bgneal@44: return u'%s %s' % (self.date.strftime('%m/%d/%Y'), self.venue.name) bgneal@44: else: bgneal@44: return self.date.strftime('%m/%d/%Y') bgneal@44: bgneal@44: class Meta: bgneal@44: ordering = ['-date', 'time']