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