annotate gpp/podcast/models.py @ 344:7eed448b399c

Fix #162; make username larger in forum posts.
author Brian Neal <bgneal@gmail.com>
date Sun, 27 Feb 2011 22:58:48 +0000
parents d424b8bae71d
children 77d878acea5e
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@224 21 link = models.URLField(verify_exists=False)
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@224 45 enclosure_url = models.URLField(verify_exists=False)
bgneal@224 46 alt_enclosure_url = models.URLField(verify_exists=False, 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))