annotate bandmap/models.py @ 1201:fe10aea76cbd tip

Add 2023 MP3 compilation links
author Brian Neal <bgneal@gmail.com>
date Sun, 24 Mar 2024 14:50:23 -0500
parents 09ed84a7394c
children
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@843 8 from django.template.loader import render_to_string
bgneal@820 9
bgneal@820 10
bgneal@822 11 class BandEntryManager(models.Manager):
bgneal@822 12 def new_entry_count(self):
bgneal@822 13 return self.filter(is_approved=False).count()
bgneal@822 14
bgneal@822 15
bgneal@820 16 class BandEntry(models.Model):
bgneal@820 17 """Represents a band entry on the band map."""
bgneal@820 18 name = models.CharField(max_length=128)
bgneal@820 19 user = models.ForeignKey(User)
bgneal@820 20 date_submitted = models.DateTimeField()
bgneal@820 21 date_approved = models.DateTimeField(null=True, blank=True)
bgneal@820 22 url = models.URLField(blank=True, max_length=200)
bgneal@820 23 location = models.CharField(max_length=255)
bgneal@820 24 lat = models.FloatField()
bgneal@820 25 lon = models.FloatField()
bgneal@820 26 note = models.CharField(max_length=255, blank=True)
bgneal@820 27 is_active = models.BooleanField(default=True, db_index=True)
bgneal@820 28 is_approved = models.BooleanField(default=False, db_index=True)
bgneal@843 29 html = models.TextField(blank=True)
bgneal@820 30
bgneal@822 31 objects = BandEntryManager()
bgneal@822 32
bgneal@820 33 class Meta:
bgneal@820 34 ordering = ['name']
bgneal@820 35 verbose_name_plural = 'band map entries'
bgneal@820 36
bgneal@820 37 def __unicode__(self):
bgneal@820 38 return u"BandMap entry for {}".format(self.name)
bgneal@820 39
bgneal@820 40 def save(self, *args, **kwargs):
bgneal@820 41 if not self.pk and not self.date_submitted:
bgneal@820 42 self.date_submitted = datetime.datetime.now()
bgneal@843 43 html = render_to_string('bandmap/balloon.html', {'band': self})
bgneal@843 44 self.html = html.strip().replace('\n', '')
bgneal@820 45 super(BandEntry, self).save(*args, **kwargs)