changeset 5:e602b5302b94

Added support for countries beside the USA.
author Brian Neal <bgneal@gmail.com>
date Thu, 14 May 2009 00:31:39 +0000
parents 432f7467543a
children fa724fb48b2c
files mysite/band/admin.py mysite/band/models.py mysite/band/views.py mysite/templates/band/gigs.html
diffstat 4 files changed, 30 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/mysite/band/admin.py	Sun Apr 19 18:36:56 2009 +0000
+++ b/mysite/band/admin.py	Thu May 14 00:31:39 2009 +0000
@@ -12,6 +12,7 @@
 from mysite.band.models import Album_Track
 from mysite.band.models import Band
 from mysite.band.models import City
+from mysite.band.models import Country
 from mysite.band.models import Fan
 from mysite.band.models import Gear
 from mysite.band.models import Gig
@@ -70,7 +71,7 @@
    model = City
 
 class CityAdmin(admin.ModelAdmin):
-   list_display = ('name', 'state')
+   list_display = ('name', 'state', 'country')
    list_filter = ('state', )
    search_fields = ('name', )
 
@@ -78,6 +79,10 @@
 
 #######################################################################
 
+admin.site.register(Country)
+
+#######################################################################
+
 class StateAdmin(admin.ModelAdmin):
    inlines = [
          CityInline,
--- a/mysite/band/models.py	Sun Apr 19 18:36:56 2009 +0000
+++ b/mysite/band/models.py	Thu May 14 00:31:39 2009 +0000
@@ -60,6 +60,18 @@
 
 #######################################################################
 
+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()
@@ -75,6 +87,7 @@
 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'
--- a/mysite/band/views.py	Sun Apr 19 18:36:56 2009 +0000
+++ b/mysite/band/views.py	Thu May 14 00:31:39 2009 +0000
@@ -77,6 +77,7 @@
    venues = set([])
    cities = set([])
    states = set([])
+   countries = set([])
    bands = set([])
    for gig in previous:
       if gig.venue.id not in venues:
@@ -85,6 +86,8 @@
          cities.add(gig.venue.city.id)
       if gig.venue.city.state and gig.venue.city.state.id not in states:
          states.add(gig.venue.city.state.id)
+      if gig.venue.city.country and gig.venue.city.country.id not in countries:
+          countries.add(gig.venue.city.country.id)
       for band in gig.bands.all():
          if band.id not in bands:
             bands.add(band.id)
@@ -93,6 +96,7 @@
    stats['venues'] = len(venues)
    stats['cities'] = len(cities)
    stats['states'] = len(states)
+   stats['countries'] = len(countries)
    stats['bands'] = len(bands)
 
    flyerGigs = Gig.objects.exclude(flyer__isnull = True).order_by('-date')
--- a/mysite/templates/band/gigs.html	Sun Apr 19 18:36:56 2009 +0000
+++ b/mysite/templates/band/gigs.html	Thu May 14 00:31:39 2009 +0000
@@ -44,6 +44,9 @@
          {% else %}
             {{ show.venue.city.name }}
          {% endif %}
+         {% ifnotequal show.venue.city.country.name "USA" %}
+            {{ show.venue.city.country.name }}
+         {% endifnotequal %}
          <br />
          {% if show.venue.phone %}
             {{ show.venue.phone }}
@@ -119,6 +122,9 @@
                {{ show.venue.name }},
             {% endif %}
             {{ show.venue.city.name }}, {{ show.venue.city.state.abbrev }}
+            {% ifnotequal show.venue.city.country.name "USA" %}
+               {{ show.venue.city.country.name }}
+            {% endifnotequal %}
          </td>
          <td width="40%">
             {% for band in show.bands.all %}
@@ -145,6 +151,7 @@
    <tr><th align="left">Number of unique venues:</th><td>{{ stats.venues }}</td></tr>
    <tr><th align="left">Number of unique cities:</th><td>{{ stats.cities }}</td></tr>
    <tr><th align="left">Number of unique states:</th><td>{{ stats.states }}</td></tr>
+   <tr><th align="left">Number of unique countries:</th><td>{{ stats.countries }}</td></tr>
    <tr><th align="left">Number of unique bands:</th><td>{{ stats.bands }}</td></tr>
 </table>
 {% endif %}