def filldb(request, cou): for x in range(0, int(cou)): q = Question(title="Question #" + str(x), text="Just a question with number " + str(x)) q.rating = x q.author_id = 1 q.added_at = date(2016, 03, 1 + x) q.save() q.added_at = date(2016, 03, 1 + x) for y in range(1, x + 2): a = Answer(text="answer #" + str(y) + " for question #" + str(x)) a.author_id = 1 q.answer_set.add(a) q.save() return HttpResponse("OK")
def filldb(request, cou): for x in range(0, int(cou)): q = Question(title = "Question #"+str(x), text = "Just a question with number "+str(x)) q.rating = x q.author_id = 1 q.added_at = date(2016, 03, 1+x) q.save() q.added_at = date(2016, 03, 1+x) for y in range(1, x+2): a = Answer(text = "answer #"+str(y)+" for question #"+str(x)) a.author_id = 1 q.answer_set.add(a) q.save() return HttpResponse("OK")
def createdata(): users = [] for i in range(3): user, created = User.objects.get_or_create(username='******' + repr(i)) if created: user.set_password('test') user.save() users += [user] questions = [] for i in range(3): numstr = repr(i) question = Question(title='Question #' + numstr, text = 'Question text #' + numstr, author = user) question.added_at = datetime.now() question.rating = 10 - i question.save() questions += [question] for i in range(10): answer = Answer(author = random.choice(users), text = 'Answer #' + repr(i), question = random.choice(questions)) answer.added_at = datetime.now() answer.save() return None