1 from django
.db
import models
2 from django
.conf
import settings
4 from mygpo
.core
.models
import UpdateInfoModel
, DeleteableModel
, SettingsModel
5 from mygpo
.users
.models
import Client
6 from mygpo
.podcasts
.models
import Podcast
9 class SubscriptionManager(models
.Manager
):
10 """ Manages subscriptions """
12 def subscribe(self
, device
, podcast
):
13 # create subscription, add history
16 def unsubscribe(self
, device
, podcast
):
17 # delete subscription, add history
21 class Subscription(DeleteableModel
):
22 """ A subscription to a podcast on a specific client """
24 # the user that subscribed to a podcast
25 user
= models
.ForeignKey(settings
.AUTH_USER_MODEL
, db_index
=True,
26 on_delete
=models
.CASCADE
)
28 # the client on which the user subscribed to the podcast
29 client
= models
.ForeignKey(Client
, db_index
=True,
30 on_delete
=models
.CASCADE
)
32 # the podcast to which the user subscribed to
33 podcast
= models
.ForeignKey(Podcast
, db_index
=True,
34 on_delete
=models
.PROTECT
)
36 # the URL that the user subscribed to; a podcast might have multiple URLs,
37 # the we want to return the users the ones they know
38 ref_url
= models
.URLField(max_length
=2048)
40 # the following fields do not use auto_now[_add] for the time of the
41 # migration, in order to store historically accurate data; once the
42 # migration is complete, this model should inherit from UpdateInfoModel
43 created
= models
.DateTimeField()
44 modified
= models
.DateTimeField()
46 objects
= SubscriptionManager()
50 ['user', 'client', 'podcast'],
58 class PodcastConfig(SettingsModel
, UpdateInfoModel
):
59 """ Settings for a podcast, independant of a device / subscription """
61 # the user for which the config is stored
62 user
= models
.ForeignKey(settings
.AUTH_USER_MODEL
, db_index
=True,
63 on_delete
=models
.CASCADE
)
65 # the podcast for which the config is stored
66 podcast
= models
.ForeignKey(Podcast
, db_index
=True,
67 on_delete
=models
.PROTECT
)