from django.core.management.base import BaseCommand
from content.models import Content
import sys
import random
class Command(BaseCommand):
def _get_string(self, prompt, reader_func=raw_input, required=True):
"""Helper method to get a non-empty string.
"""
string = ''
while not string:
string = reader_func(prompt + ': ')
if not required:
break
return string
def handle(self, **kwargs):
n = self._get_string('Number')
# random_number = random.randint(0,400)
# n = random_number
words = open('/usr/share/dict/words').readlines()
title= []
for i in range(2):
title.append(words[random.randrange(0, len(words))][:-1])
if title is not None:
title = ' '.join(title)
paragraph = []
for i in range(int(n)):
paragraph.append(words[random.randrange(0, len(words))][:-1])
if paragraph is not None:
paragraph = ' '.join(paragraph)
content = Content(title=title, paragraph=paragraph)
content.save()
print 'Content successfully added'
Comments