annotate bandmap/models.py @ 821:71db8076dc3d

Bandmap WIP: geocoding integrated with add form. Add form works. Before submitting the form, client side JS makes a geocode request to Google and populates hidden lat/lon fields with the result. Successfully created a model instance on the server side. Still need to update admin dashboard, admin approval, and give out badges for adding bands to the map. Once that is done, then work on displaying the map with filtering.
author Brian Neal <bgneal@gmail.com>
date Tue, 23 Sep 2014 20:40:31 -0500
parents 9a0df7bd2409
children 2c4f28b1c12a
rev   line source
bgneal@820 1 """Models for the bandmap application.
bgneal@820 2
bgneal@820 3 """
bgneal@820 4 import datetime
bgneal@820 5
bgneal@820 6 from django.db import models
bgneal@820 7 from django.contrib.auth.models import User
bgneal@820 8
bgneal@820 9
bgneal@820 10 class BandEntry(models.Model):
bgneal@820 11 """Represents a band entry on the band map."""
bgneal@820 12 name = models.CharField(max_length=128)
bgneal@820 13 user = models.ForeignKey(User)
bgneal@820 14 date_submitted = models.DateTimeField()
bgneal@820 15 date_approved = models.DateTimeField(null=True, blank=True)
bgneal@820 16 url = models.URLField(blank=True, max_length=200)
bgneal@820 17 location = models.CharField(max_length=255)
bgneal@820 18 lat = models.FloatField()
bgneal@820 19 lon = models.FloatField()
bgneal@820 20 note = models.CharField(max_length=255, blank=True)
bgneal@820 21 is_active = models.BooleanField(default=True, db_index=True)
bgneal@820 22 is_approved = models.BooleanField(default=False, db_index=True)
bgneal@820 23
bgneal@820 24 class Meta:
bgneal@820 25 ordering = ['name']
bgneal@820 26 verbose_name_plural = 'band map entries'
bgneal@820 27
bgneal@820 28 def __unicode__(self):
bgneal@820 29 return u"BandMap entry for {}".format(self.name)
bgneal@820 30
bgneal@820 31 def save(self, *args, **kwargs):
bgneal@820 32 if not self.pk and not self.date_submitted:
bgneal@820 33 self.date_submitted = datetime.datetime.now()
bgneal@820 34 super(BandEntry, self).save(*args, **kwargs)