Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

management commands django

from django.core.management.base import BaseCommand, CommandError
from polls.models import Question as Poll

class Command(BaseCommand):
    help = 'Closes the specified poll for voting'

    def add_arguments(self, parser):
        parser.add_argument('poll_ids', nargs='+', type=int)

    def handle(self, *args, **options):
        for poll_id in options['poll_ids']:
            try:
                poll = Poll.objects.get(pk=poll_id)
            except Poll.DoesNotExist:
                raise CommandError('Poll "%s" does not exist' % poll_id)

            poll.opened = False
            poll.save()

            self.stdout.write(self.style.SUCCESS('Successfully closed poll "%s"' % poll_id))
Comment

management command in django

from django.core.management.base import BaseCommand
from django.utils import timezone

class Command(BaseCommand):
    help = 'Displays current time'

    def handle(self, *args, **kwargs):
        time = timezone.now().strftime('%X')
        self.stdout.write("It's now %s" % time)
Comment

PREVIOUS NEXT
Code Example
Python :: python tkinter importieren 
Python :: python string formatting - padding 
Python :: binary search tree implementation in python 
Python :: binary tree python 
Python :: accumulator programming python 
Python :: groupbycolumn 
Python :: pandas trim string of all cells 
Python :: histogram python 
Python :: set method in python 
Python :: how to get the top 100 frequent words on a python dataframe colummn 
Python :: how to open py file without console 
Python :: how to set environment variable in pycharm 
Python :: 12 month movinf average in python for dataframe 
Python :: pandas split cell into multiple columns 
Python :: creating python classes 
Python :: numpy flatten along two axes 
Python :: decorators in python 
Python :: how to input a picture into opencv raspberry pi 
Python :: python lock file 
Python :: matplotlib tick label position left and right x axis 
Python :: python dictionary with dot notation 
Python :: time in python 
Python :: correlation meaning 
Python :: jupyter read excel 
Python :: customise the django rest api view 
Python :: NumPy roll Example 
Python :: how to define a functio in python 
Python :: dataclass in python 
Python :: float python 
Python :: repl.it install packages python 
ADD CONTENT
Topic
Content
Source link
Name
6+2 =