bgneal@820: """Models for the bandmap application. bgneal@820: bgneal@820: """ bgneal@820: import datetime bgneal@820: bgneal@820: from django.db import models bgneal@820: from django.contrib.auth.models import User bgneal@820: bgneal@820: bgneal@822: class BandEntryManager(models.Manager): bgneal@822: def new_entry_count(self): bgneal@822: return self.filter(is_approved=False).count() bgneal@822: bgneal@822: bgneal@820: class BandEntry(models.Model): bgneal@820: """Represents a band entry on the band map.""" bgneal@820: name = models.CharField(max_length=128) bgneal@820: user = models.ForeignKey(User) bgneal@820: date_submitted = models.DateTimeField() bgneal@820: date_approved = models.DateTimeField(null=True, blank=True) bgneal@820: url = models.URLField(blank=True, max_length=200) bgneal@820: location = models.CharField(max_length=255) bgneal@820: lat = models.FloatField() bgneal@820: lon = models.FloatField() bgneal@820: note = models.CharField(max_length=255, blank=True) bgneal@820: is_active = models.BooleanField(default=True, db_index=True) bgneal@820: is_approved = models.BooleanField(default=False, db_index=True) bgneal@820: bgneal@822: objects = BandEntryManager() bgneal@822: bgneal@820: class Meta: bgneal@820: ordering = ['name'] bgneal@820: verbose_name_plural = 'band map entries' bgneal@820: bgneal@820: def __unicode__(self): bgneal@820: return u"BandMap entry for {}".format(self.name) bgneal@820: bgneal@820: def save(self, *args, **kwargs): bgneal@820: if not self.pk and not self.date_submitted: bgneal@820: self.date_submitted = datetime.datetime.now() bgneal@820: super(BandEntry, self).save(*args, **kwargs)