[API] don't encode query string
[mygpo.git] / mygpo / categories / models.py
blobaba892574190a7c00f0118cabcfee949568a69c2
1 from django.db import models
3 from mygpo.core.models import UpdateInfoModel
4 from mygpo.podcasts.models import Podcast
7 class Category(UpdateInfoModel):
8 """ A category of podcasts """
10 title = models.CharField(max_length=1000, null=False, blank=False,
11 unique=True)
13 num_entries = models.IntegerField()
15 class Meta:
16 verbose_name = 'Category'
17 verbose_name_plural = 'Categories'
19 index_together = [
20 ('modified', 'num_entries'),
23 def save(self, *args, **kwargs):
24 self.num_entries = self.entries.count()
25 super(Category, self).save(*args, **kwargs)
27 @property
28 def podcasts(self):
29 return self.entries.prefetch_related('podcast', 'podcast__slugs')
31 @property
32 def clean_title(self):
33 return self.title.replace('\n', ' ')
35 @property
36 def tag(self):
37 return self.tags.first().tag
40 class CategoryEntry(UpdateInfoModel,):
41 """ A podcast in a category """
43 category = models.ForeignKey(Category, related_name='entries',
44 on_delete=models.CASCADE)
46 podcast = models.ForeignKey(Podcast,
47 on_delete=models.CASCADE)
49 class Meta:
50 unique_together = [
51 ('category', 'podcast'),
54 index_together = [
55 ('category', 'modified'),
59 class CategoryTag(models.Model):
61 tag = models.SlugField(unique=True)
63 category = models.ForeignKey(Category, related_name='tags',
64 on_delete=models.CASCADE)