Mercurial > public > madeira
view gigs/models.py @ 90:447d75d1e21d
For Django 1.5: localflavor is deprecated in preference to a 3rd party app.
author | Brian Neal <bgneal@gmail.com> |
---|---|
date | Tue, 27 Aug 2013 20:03:32 -0500 |
parents | e2868ad47a1e |
children |
line wrap: on
line source
""" Models for the gigs application. """ from django.db import models from localflavor.us.models import USStateField from 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']