view gigs/models.py @ 93:388be986392e

For Django 1.5: The adminmedia template tags library was removed. Doesn't look like I was using it anyway.
author Brian Neal <bgneal@gmail.com>
date Wed, 28 Aug 2013 18:32:57 -0500
parents 447d75d1e21d
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']