annotate gigs/models.py @ 115:44a635748fb9

Boostrap: home page.
author Brian Neal <bgneal@gmail.com>
date Sun, 20 Oct 2013 17:35:39 -0500
parents 447d75d1e21d
children
rev   line source
bgneal@44 1 """
bgneal@44 2 Models for the gigs application.
bgneal@44 3
bgneal@44 4 """
bgneal@44 5 from django.db import models
bgneal@90 6 from localflavor.us.models import USStateField
bgneal@90 7 from localflavor.us.models import PhoneNumberField
bgneal@44 8
bgneal@44 9 from photologue.models import Photo
bgneal@44 10
bgneal@44 11
bgneal@44 12 class Country(models.Model):
bgneal@44 13 name = models.CharField(max_length=64)
bgneal@44 14
bgneal@44 15 class Meta:
bgneal@44 16 ordering = ['name']
bgneal@44 17 verbose_name_plural = 'Countries'
bgneal@44 18
bgneal@44 19 def __unicode__(self):
bgneal@44 20 return self.name
bgneal@44 21
bgneal@44 22
bgneal@44 23 class State(models.Model):
bgneal@44 24 name = models.CharField(max_length=16)
bgneal@44 25 abbrev = USStateField()
bgneal@44 26
bgneal@44 27 class Meta:
bgneal@44 28 ordering = ['name']
bgneal@44 29
bgneal@44 30 def __unicode__(self):
bgneal@44 31 return self.name
bgneal@44 32
bgneal@44 33
bgneal@44 34 class City(models.Model):
bgneal@44 35 name = models.CharField(max_length=50)
bgneal@44 36 state = models.ForeignKey(State, null=True, blank=True)
bgneal@44 37 country = models.ForeignKey(Country, null=True, blank=True)
bgneal@44 38
bgneal@44 39 class Meta:
bgneal@44 40 verbose_name_plural = 'Cities'
bgneal@44 41 ordering = ['name']
bgneal@44 42
bgneal@44 43 def __unicode__(self):
bgneal@44 44 if self.state:
bgneal@44 45 return u'%s, %s' % (self.name, self.state.abbrev)
bgneal@90 46
bgneal@44 47 return self.name
bgneal@44 48
bgneal@44 49
bgneal@44 50 class Venue(models.Model):
bgneal@44 51 name = models.CharField(max_length=50)
bgneal@64 52 url = models.URLField(blank=True)
bgneal@44 53 address = models.CharField(max_length=255, blank=True)
bgneal@44 54 phone = PhoneNumberField(help_text="Format: XXX-XXX-XXXX", blank=True)
bgneal@44 55 city = models.ForeignKey(City)
bgneal@44 56
bgneal@44 57 class Meta:
bgneal@44 58 ordering = ['name']
bgneal@44 59
bgneal@44 60 def __unicode__(self):
bgneal@44 61 return self.name
bgneal@44 62
bgneal@44 63
bgneal@44 64 class Band(models.Model):
bgneal@44 65 name = models.CharField(max_length=64)
bgneal@64 66 url = models.URLField(blank=True)
bgneal@44 67
bgneal@44 68 class Meta:
bgneal@44 69 ordering = ['name']
bgneal@44 70
bgneal@44 71 def __unicode__(self):
bgneal@44 72 return self.name
bgneal@44 73
bgneal@44 74
bgneal@44 75 class Gig(models.Model):
bgneal@44 76 title = models.CharField(max_length=50, blank=True,
bgneal@44 77 help_text="Optional; e.g. Some Festival")
bgneal@64 78 url = models.URLField(blank=True,
bgneal@44 79 help_text="Optional; e.g. Some Festival's Website")
bgneal@44 80 date = models.DateField(db_index=True)
bgneal@44 81 time = models.TimeField(null=True, blank=True)
bgneal@44 82 venue = models.ForeignKey(Venue, null=True, blank=True)
bgneal@44 83 notes = models.TextField(blank=True)
bgneal@44 84 bands = models.ManyToManyField(Band, blank=True)
bgneal@44 85 flyer = models.ForeignKey(Photo, null=True, blank=True,
bgneal@44 86 related_name='gig_flyers')
bgneal@44 87
bgneal@44 88 def __unicode__(self):
bgneal@44 89 if self.title:
bgneal@44 90 return u'%s %s %s' % (self.date.strftime('%m/%d/%Y'), self.title, self.venue.name)
bgneal@44 91 elif self.venue:
bgneal@44 92 return u'%s %s' % (self.date.strftime('%m/%d/%Y'), self.venue.name)
bgneal@44 93 else:
bgneal@44 94 return self.date.strftime('%m/%d/%Y')
bgneal@44 95
bgneal@44 96 class Meta:
bgneal@44 97 ordering = ['-date', 'time']