3 from django
.core
.management
.base
import BaseCommand
4 from django
.contrib
.auth
import get_user_model
6 from mygpo
.podcasts
.models
import Podcast
7 from mygpo
.publisher
.models
import PublishedPodcast
10 class Command(BaseCommand
):
12 Makes the specified user a publisher for the specified podcast.
14 The user is specified by its username, the podcast is specified by one of
18 def handle(self
, *args
, **options
):
21 print('Usage: ./manage.py make-publisher <username> <podcast-url-1> [<podcast-url-2> ...]', file=sys
.stderr
)
26 User
= get_user_model()
27 user
= User
.objects
.get(username
=username
)
29 print('User %s does not exist' % username
, file=sys
.stderr
)
33 podcasts
= Podcast
.objects
.filter(urls__url__in
=urls
)
34 PublishedPodcast
.objects
.get_or_create(user
, podcasts
)