Mercurial > public > madeira
diff gigs/models.py @ 71:e2868ad47a1e
For Django 1.4, using the new manage.py.
author | Brian Neal <bgneal@gmail.com> |
---|---|
date | Sat, 14 Apr 2012 16:40:29 -0500 |
parents | madeira/gigs/models.py@e17fc6bbb9b0 |
children | 447d75d1e21d |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/gigs/models.py Sat Apr 14 16:40:29 2012 -0500 @@ -0,0 +1,97 @@ +""" +Models for the gigs application. + +""" +from django.db import models +from django.contrib.localflavor.us.models import USStateField +from django.contrib.localflavor.us.models import PhoneNumberField + +from photologue.models import Photo + + +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 u'%s, %s' % (self.name, self.state.abbrev) + + return self.name + + +class Venue(models.Model): + name = models.CharField(max_length=50) + url = models.URLField(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(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(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, + related_name='gig_flyers') + + 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 self.date.strftime('%m/%d/%Y') + + class Meta: + ordering = ['-date', 'time']