M
M
Michael2017-03-10 23:26:28
Django
Michael, 2017-03-10 23:26:28

Multiple buttons in a django form?

There is a model in which a question and three possible answers.
It is necessary to implement a form in which there will be three buttons, i.e. answer options.
How to pass several buttons in the form, and in the view to process which one was pressed?
Or is there another solution?
Model example

class Primer(models.Model):	
  user = models.ForeignKey(User)
  title = models.CharField("Заголовок", max_length=55)
  pub_date = models.DateTimeField("Дата", default=timezone.now)
  quest_1 = models.CharField("Контрольный вопрос к письму", max_length=300)
  quest_1_ans_1 = models.CharField("Вариант ответа №1", max_length=30)
  quest_1_ans_2 = models.CharField("Вариант ответа №2", max_length=30)
  quest_1_ans_3 = models.CharField("Вариант ответа №3", max_length=30)
  var_one = models.IntegerField("Укажите номер правильного ответа на вопрос", default=1)

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Shamsudin Serderov, 2017-03-10
@DJWOMS1

<form action="/" method="post">
    {% csrf_token %}


    <td><input type="submit" value="Изменить" name="_edit"></td>
    <td><input type="submit" value="Удалить" name="_delete"></td>
</tr>

if request.POST:
    if '_edit' in request.POST:
         do_edit()
    elif '_delete' in request.POST:
         do_delete()

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question