Skip to content

Instantly share code, notes, and snippets.

@morty
Created November 17, 2016 10:59
Show Gist options
  • Save morty/f8b5a4c1018e173aa57b6b2ed7037517 to your computer and use it in GitHub Desktop.
Save morty/f8b5a4c1018e173aa57b6b2ed7037517 to your computer and use it in GitHub Desktop.
Simple Django management command to run the application at a given timestamp
from django.core.management.base import BaseCommand
from django.core.management import call_command
from freezegun import freeze_time
class Command(BaseCommand):
help = 'Run application at given time'
def add_arguments(self, parser):
parser.add_argument('timestamp', nargs='?',
help='Timestamp to run application at')
parser.add_argument('addrport', nargs='?',
help='Optional port number, or ipaddr:port')
def handle(self, *args, **options):
with freeze_time(options['timestamp']):
call_command('runserver', *args, **options)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment