Exemplo n.º 1
0
 def save(self, commit=True):
     answer = Answer(text=self.cleaned_data.get('text'))
     answer.author = self.author
     answer.question = self.question
     if commit:
         answer.save()
     return answer
Exemplo n.º 2
0
def create_answer(request, question_id):
    ans = Answer()
    ans.question = Question.objects.get(pk=question_id)
    ans.author = request.user
    ans.content = request.POST['content']
    ans.is_better = False
    ans.save()
    return HttpResponseRedirect(reverse('question-details', args=(question_id,)))
Exemplo n.º 3
0
def answer(question_id):
    form = answerForm()
    question_alias = Question.query.filter(Question.id==question_id).first().alias
    if form.validate_on_submit():
        item = Answer()
        form.populate_obj(item)
        item.author = login.current_user.get_id()
        item.question = question_id
        db.session.add(item)
        db.session.commit()
    return redirect('/question/'+question_alias+'/')    
Exemplo n.º 4
0
    def handle(self, *args, **options):
        fake = Factory.create()

        min_number = int(options['min_number'])
        max_number = int(options['max_number'])

        users = User.objects.all()[1:]
        questions = Question.objects.all()

        for q in questions:
            for i in range(0, randint(min_number, max_number)):
                ans = Answer()
                ans.text = fake.paragraph(nb_sentences=randint(2, 10),
                                          variable_nb_sentences=True)
                ans.author = choice(users)
                ans.question = q
                ans.save()