[Migration] fix issues with users from Django Auth
[mygpo.git] / mygpo / publisher / models.py
blob75a196391a8029bfff3a5e80c119884643ba1da5
1 """ This module contains models for the publisher pages """
3 from django.db import models
4 from django.conf import settings
6 from mygpo.podcasts.models import Podcast
8 import logging
9 logger = logging.getLogger(__name__)
12 class PublishedPodcastManager(models.Manager):
13 """ Manager for the PublishedPodcast model """
15 def publish_podcasts(self, user, podcasts):
16 existed, created = 0, 0
17 for podcast in podcasts:
18 pp, _ = PublishedPodcast.objects.get_or_create(
19 publisher=user,
20 podcast=podcast,
23 if created:
24 created += 1
25 logger.info('Created publisher permissions for %r on %r',
26 user, podcast)
27 else:
28 existed += 1
29 logger.info('Publisher permissions for %r on %r already exist',
30 user, podcast)
33 return created, existed
36 class PublishedPodcast(models.Model):
37 publisher = models.ForeignKey(settings.AUTH_USER_MODEL)
38 podcast = models.ForeignKey(Podcast)
40 class Meta:
41 unique_together = (
42 ('publisher', 'podcast'),
45 objects = PublishedPodcastManager()