我的django应用程序中有一个表单,其中包含一个下拉列表。
Models.py
class Quiz(models.Model):
mtypes = (('A', 'A'), ('B', 'B'), ('C', 'C'), ('D', 'D'), ('E', 'E'))
material_type = models.CharField(max_length=255, default=0, choices=mtypes)
Views.py
class QuizCreateView(CreateView):
model = Quiz
fields = ('material_type')
template_name = 'classroom/teachers/quiz_add_form.html'
def form_valid (self, form):
quiz = form.save(commit=False)
quiz.owner = self.request.user
quiz.save()
return redirect('teachers:quiz_change', quiz.pk)
html
{% load crispy_forms_tags %}
{% block content %}
<nav aria-label="breadcrumb">
<ol class="breadcrumb">
<li class="breadcrumb-item"><a href="{% url 'teachers:quiz_change_list' %}">RFQs</a></li>
<li class="breadcrumb-item active" aria-current="page">Post New RFQ</li>
</ol>
</nav>
<h2 class="mb-3">Post New RFQ</h2>
{% csrf_token %}
{#<h3>Material Details</h3>#}
<div class="form-group col-md-4 mb-0">
{{ form.material_type|as_crispy_field }}
</div>
<button type="submit" class="btn btn-success">Save</button>
我可以将material_type显示为下拉列表,但是可以向此DropDown添加复选框吗? This是我能找到的最接近的东西,但是列出的库中的文档并不清楚。 我该怎么办?
我所拥有的:
我想要什么:
针对A,B,C的复选框。