comparison podcast/models.py @ 581:ee87ea74d46b

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