suffixdomains command for dev purpose

This commit is contained in:
Élie Bouttier 2017-08-12 22:25:17 +02:00
parent 6fc3457ddc
commit c1c5b015c7
1 changed files with 27 additions and 0 deletions

View File

@ -0,0 +1,27 @@
from django.core.management.base import BaseCommand
from django.contrib.sites.models import Site
class Command(BaseCommand):
help = 'Add a suffix to all site domains.'
def add_arguments(self, parser):
parser.add_argument('suffix')
def handle(self, *args, **options):
answer = input("""You are about to change all site domains.
Are you sure you want to do this?
Type 'yes' to continue, or 'no' to cancel: """)
self.stdout.write('\n')
if answer != "yes":
self.stdout.write(self.style.NOTICE('Action cancelled.'))
return
for site in Site.objects.all():
site.domain = site.domain + options['suffix']
site.save()
self.stdout.write(self.style.SUCCESS('All domains modified.'))