refactoring
[mygpo.git] / mygpo / data / models.py
blob5e97db3d7b4d81282b0eed7da05947af291b9c83
1 from django.db import models
2 from django.contrib.auth.models import User
3 from mygpo.api.models import Podcast, Episode, Device
6 class PodcastTagManager(models.Manager):
8 def top_tags(self):
9 return self.raw("select *, count(id) as entries from podcast_tags group by tag order by entries desc")
11 class PodcastTag(models.Model):
12 tag = models.CharField(max_length=100)
13 podcast = models.ForeignKey(Podcast)
14 source = models.CharField(max_length=100)
15 user = models.ForeignKey(User, null=True)
16 weight = models.IntegerField(default=1)
18 objects = PodcastTagManager()
20 class Meta:
21 db_table = 'podcast_tags'
22 unique_together = ('podcast', 'source', 'user', 'tag')
25 class HistoricPodcastData(models.Model):
26 podcast = models.ForeignKey(Podcast)
27 date = models.DateField()
28 subscriber_count = models.IntegerField()
30 class Meta:
31 db_table = 'historic_podcast_data'
32 unique_together = ('podcast', 'date')
35 class BackendSubscription(models.Model):
36 """
37 Represents the data in the subscriptions table, which
38 contains all subscriptions, even those for currently deleted devices
39 """
40 device = models.ForeignKey(Device)
41 podcast = models.ForeignKey(Podcast)
42 user = models.ForeignKey(User)
43 subscribed_since = models.DateTimeField()
45 class Meta:
46 unique_together = ('device', 'podcast', 'user')
47 db_table = 'subscriptions'
50 class Listener(models.Model):
51 device = models.ForeignKey(Device)
52 user = models.ForeignKey(User)
53 episode = models.ForeignKey(Episode)
54 podcast = models.ForeignKey(Podcast)
55 first_listened = models.DateTimeField()
56 last_listened = models.DateTimeField()
58 class Meta:
59 db_table = 'listeners'
60 managed = False
63 class RelatedPodcast(models.Model):
64 ref_podcast = models.ForeignKey(Podcast, related_name='ref_podcast')
65 rel_podcast = models.ForeignKey(Podcast, related_name='rel_podcast')
66 priority = models.IntegerField()
68 class Meta:
69 db_table = 'related_podcasts'
72 class SuggestionBlacklist(models.Model):
73 user = models.ForeignKey(User)
74 podcast = models.ForeignKey(Podcast)
76 class Meta:
77 db_table = 'suggestion_blacklist'
78 managed = False