class Command(BaseCommand):
    help = 'Does some magical work'

def handle(self, *args, **options):
    """ Do your work here """
self.stdout.write('There are {} things!'.format(MyModel.objects.count()))
Using Django models in external python script