annotate podcast/models.py @ 797:c37760a79059

Tweak contest detail template for pluralization.
author Brian Neal <bgneal@gmail.com>
date Sat, 05 Jul 2014 13:35:47 -0500
parents ee87ea74d46b
children e932f2ecd4a7
rev   line source
bgneal@277 1 """
bgneal@277 2 Models for the podcast application.
bgneal@277 3
bgneal@277 4 """
bgneal@277 5 import datetime
gremmie@1 6
gremmie@1 7 from django.db import models
gremmie@1 8
bgneal@277 9
gremmie@1 10 EXPLICIT_CHOICES = (
bgneal@224 11 ('yes', 'Yes'),
bgneal@224 12 ('no', 'No'),
bgneal@224 13 ('clean', 'Clean'),
bgneal@224 14 )
gremmie@1 15
gremmie@1 16
gremmie@1 17 class Channel(models.Model):
bgneal@224 18 """Model to represent the Channel properties"""
gremmie@1 19
bgneal@224 20 title = models.CharField(max_length=255)
bgneal@572 21 link = models.URLField()
bgneal@224 22 language = models.CharField(max_length=16)
bgneal@224 23 copyright = models.CharField(max_length=255)
bgneal@224 24 subtitle = models.CharField(max_length=255)
bgneal@224 25 author = models.CharField(max_length=64)
bgneal@224 26 description = models.CharField(max_length=255)
bgneal@224 27 owner_name = models.CharField(max_length=64)
bgneal@224 28 owner_email = models.EmailField()
bgneal@224 29 image = models.ImageField(upload_to='podcast')
bgneal@224 30 category = models.CharField(max_length=64)
bgneal@224 31 explicit = models.CharField(max_length=8, choices=EXPLICIT_CHOICES)
bgneal@224 32 keywords = models.CharField(max_length=255)
gremmie@1 33
bgneal@224 34 def __unicode__(self):
bgneal@224 35 return self.title
gremmie@1 36
gremmie@1 37
gremmie@1 38 class Item(models.Model):
bgneal@224 39 """Model to represent a channel item"""
bgneal@224 40 channel = models.ForeignKey(Channel)
bgneal@224 41 title = models.CharField(max_length=255)
bgneal@224 42 author = models.CharField(max_length=255)
bgneal@224 43 subtitle = models.CharField(max_length=255)
bgneal@224 44 summary = models.TextField()
bgneal@572 45 enclosure_url = models.URLField()
bgneal@572 46 alt_enclosure_url = models.URLField(blank=True)
bgneal@224 47 enclosure_length = models.IntegerField()
bgneal@224 48 enclosure_type = models.CharField(max_length=32)
bgneal@224 49 guid = models.CharField(max_length=255)
bgneal@277 50 pubdate = models.DateTimeField(db_index=True)
bgneal@224 51 duration = models.CharField(max_length=16)
bgneal@224 52 keywords = models.CharField(max_length=255)
bgneal@224 53 explicit = models.CharField(max_length=8, choices=EXPLICIT_CHOICES)
bgneal@277 54 update_date = models.DateTimeField(db_index=True, blank=True)
gremmie@1 55
bgneal@224 56 @models.permalink
bgneal@224 57 def get_absolute_url(self):
bgneal@224 58 return ('podcast.views.detail', [str(self.id)])
gremmie@1 59
bgneal@224 60 def __unicode__(self):
bgneal@224 61 return self.title
gremmie@1 62
bgneal@224 63 class Meta:
bgneal@224 64 ordering = ('-pubdate', )
bgneal@226 65 verbose_name = 'podcast'
bgneal@226 66 verbose_name_plural = 'podcasts'
gremmie@1 67
bgneal@277 68 def save(self, *args, **kwargs):
bgneal@277 69 if not self.id:
bgneal@277 70 if not self.pubdate:
bgneal@277 71 self.pubdate = datetime.datetime.now()
bgneal@277 72 self.update_date = self.pubdate
bgneal@277 73 else:
bgneal@277 74 self.update_date = datetime.datetime.now()
bgneal@277 75 super(Item, self).save(*args, **kwargs)
bgneal@277 76
bgneal@224 77 def search_title(self):
bgneal@224 78 return "%s: %s" % (self.title, self.subtitle)
bgneal@224 79
bgneal@224 80 def search_summary(self):
bgneal@224 81 return u"\n".join((self.subtitle, self.summary, self.keywords))
bgneal@487 82
bgneal@487 83 def ogp_tags(self):
bgneal@487 84 """
bgneal@487 85 Returns a dict of Open Graph Protocol meta tags.
bgneal@487 86
bgneal@487 87 """
bgneal@487 88 title = "%s: %s; %s" % (self.channel.title, self.title, self.subtitle)
bgneal@487 89 return {
bgneal@487 90 'og:title': title,
bgneal@487 91 'og:type': 'article',
bgneal@487 92 'og:url': self.get_absolute_url(),
bgneal@487 93 'og:description': self.subtitle,
bgneal@487 94 'og:audio': self.enclosure_url,
bgneal@487 95 'og:audio:title': title,
bgneal@487 96 'og:audio:artist': 'Various',
bgneal@487 97 'og:audio:type': self.enclosure_type,
bgneal@487 98 }