annotate bandmap/models.py @ 822:2c4f28b1c12a

Band map WIP: update admin dashboard for new band map entries.
author Brian Neal <bgneal@gmail.com>
date Wed, 24 Sep 2014 19:53:36 -0500
parents 9a0df7bd2409
children 09ed84a7394c
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@822 10 class BandEntryManager(models.Manager):
bgneal@822 11 def new_entry_count(self):
bgneal@822 12 return self.filter(is_approved=False).count()
bgneal@822 13
bgneal@822 14
bgneal@820 15 class BandEntry(models.Model):
bgneal@820 16 """Represents a band entry on the band map."""
bgneal@820 17 name = models.CharField(max_length=128)
bgneal@820 18 user = models.ForeignKey(User)
bgneal@820 19 date_submitted = models.DateTimeField()
bgneal@820 20 date_approved = models.DateTimeField(null=True, blank=True)
bgneal@820 21 url = models.URLField(blank=True, max_length=200)
bgneal@820 22 location = models.CharField(max_length=255)
bgneal@820 23 lat = models.FloatField()
bgneal@820 24 lon = models.FloatField()
bgneal@820 25 note = models.CharField(max_length=255, blank=True)
bgneal@820 26 is_active = models.BooleanField(default=True, db_index=True)
bgneal@820 27 is_approved = models.BooleanField(default=False, db_index=True)
bgneal@820 28
bgneal@822 29 objects = BandEntryManager()
bgneal@822 30
bgneal@820 31 class Meta:
bgneal@820 32 ordering = ['name']
bgneal@820 33 verbose_name_plural = 'band map entries'
bgneal@820 34
bgneal@820 35 def __unicode__(self):
bgneal@820 36 return u"BandMap entry for {}".format(self.name)
bgneal@820 37
bgneal@820 38 def save(self, *args, **kwargs):
bgneal@820 39 if not self.pk and not self.date_submitted:
bgneal@820 40 self.date_submitted = datetime.datetime.now()
bgneal@820 41 super(BandEntry, self).save(*args, **kwargs)