我正在使用多选库在模板中呈现复选框字段,然后将其存储在数据库中。我能够正确执行此操作,但是仅以此格式复选框加载数据,当将这些复选框的内容显示为字符串时,显示的内容为“无”,而不是标记的复选框的内容。如何从此复选框收集数据或正确显示数据?还有其他方法可以更轻松地做到这一点吗?
models.py
n_dentes = (
('18', '18'),
('17', '17'),
('16', '16'),
('15', '15'),
('14', '14'),
('13', '13'),
('12', '12'),
('11', '11'),
('21', '21'),
('22', '22'),
('23', '23'),
('24', '24'),
('25', '25'),
('26', '26'),
('27', '27'),
('28', '28'),
('48', '48'),
('47', '47'),
('46', '46'),
('45', '45'),
('44', '44'),
('43', '43'),
('42', '42'),
('41', '41'),
('31', '31'),
('32', '32'),
('33', '33'),
('34', '34'),
('35', '35'),
('36', '36'),
('37', '37'),
('38', '38'),
)
class pregao(models.Model):
tipo = models.CharField(_('Tipo de serviço'), max_length=100, default=' ')
dente = MultiSelectField(_('Dente'), choices=n_dentes, default=' ', max_length=100)
template.html
{% extends 'baseR.html' %}
{% load static %}
{% block title %} Novo pregão - SMILE 3D {% endblock %}
{% block tamanho %} 2500px {% endblock %}
{% load bootstrap %}
{% load widget_tweaks %}
{% block main %}
{% for field in form.visible_fields %}
{% endfor %}
<map name="dentes">
<label for="id_dente_0"><area shape="rect" coords="100,74,122,150" alt=""></label>
<label for="id_dente_1"><area shape="rect" coords="127,72,148,148" alt=""></label>
<label for="id_dente_2"><area shape="rect" coords="152,70,173,150" alt=""></label>
<label for="id_dente_3"><area shape="rect" coords="176,71,193,150" alt=""></label>
<label for="id_dente_4"><area shape="rect" coords="196,71,214,150" alt=""></label>
<label for="id_dente_5"><area shape="rect" coords="216,68,240,150" alt=""></label>
<label for="id_dente_6"><area shape="rect" coords="237,68,257,150" alt=""></label>
<label for="id_dente_7"><area shape="rect" coords="257,67,275,150" alt=""></label>
<label for="id_dente_8"><area shape="rect" coords="280,65,299,150" alt=""></label>
<label for="id_dente_9"><area shape="rect" coords="300,65,317,150" alt=""></label>
<label for="id_dente_10"><area shape="rect" coords="322,63,339,150" alt=""></label>
<label for="id_dente_11"><area shape="rect" coords="344,65,359,150" alt=""></label>
<label for="id_dente_12"><area shape="rect" coords="364,63,379,150" alt=""></label>
<label for="id_dente_13"><area shape="rect" coords="383,67,404,150" alt=""></label>
<label for="id_dente_14"><area shape="rect" coords="407,69,431,150" alt=""></label>
<label for="id_dente_15"><area shape="rect" coords="434,79,458,150" alt=""></label>
<label for="id_dente_16"><area shape="rect" coords="98,152,118,222" alt=""></label>
<label for="id_dente_17"><area shape="rect" coords="121,152,142,229" alt=""></label>
<label for="id_dente_18"><area shape="rect" coords="147,152,169,229" alt=""></label>
<label for="id_dente_19"><area shape="rect" coords="175,152,192,231" alt=""></label>
<label for="id_dente_20"><area shape="rect" coords="193,152,212,230" alt=""></label>
<label for="id_dente_21"><area shape="rect" coords="214,152,231,231" alt=""></label>
<label for="id_dente_22"><area shape="rect" coords="237,152,252,231" alt=""></label>
<label for="id_dente_23"><area shape="rect" coords="254,152,272,231" alt=""></label>
<label for="id_dente_24"><area shape="rect" coords="278,152,302,231" alt=""></label>
<label for="id_dente_25"><area shape="rect" coords="299,152,324,231" alt=""></label>
<label for="id_dente_26"><area shape="rect" coords="318,152,341,231" alt=""></label>
<label for="id_dente_27"><area shape="rect" coords="339,152,363,231" alt=""></label>
<label for="id_dente_28"><area shape="rect" coords="357,152,384,231" alt=""></label>
<label for="id_dente_29"><area shape="rect" coords="377,152,407,225" alt=""></label>
<label for="id_dente_30"><area shape="rect" coords="405,152,436,225" alt=""></label>
<label for="id_dente_31"><area shape="rect" coords="431,152,461,225" alt=""></label>
</map>
<div class="row b2">
<div class="col-1"></div>
<div class="col-10" >
<h3 style="color:royalblue">Insira seu novo pregão: </h3>
<form method="post" novalidate>
<p style="color: grey; font-size:12px;">Clique sobre o centro do dente para marcá-lo:</p>
<img src="/media/site/Quadrantes.jpg" class="img-responsive img-pregao" style="margin-left:10em;" usemap="dentes">
{% csrf_token %}
<div class="form-group">
<hr>
<label style="border:none;">*Dente:</label>
<ul id="id_dente" class="form-control" style="display:inline; margin-left:50px;">
<br>
<br><br>
<p style="color:red; font-style:italic; margin-top:-45px; font-size:20px;">Quadrante superior: </p>
<hr class="check">
<br>
<p style="color:blue; font-style:italic; font-size:17px;">Esquerda:            Direita:</p>
<li style="display:inline-block;"><label for="id_dente_0"><input type="checkbox" name="dente" value="18" placeholder="" class="form-control" id="id_dente_0" />18</label>
</li>
<li style="display:inline-block;"><label for="id_dente_1"><input type="checkbox" name="dente" value="17" placeholder="" class="form-control" id="id_dente_1" />
17</label>
</li>
<li style="display:inline-block;"><label for="id_dente_2"><input type="checkbox" name="dente" value="16" placeholder="" class="form-control" id="id_dente_2" />
16</label>
</li>
<li style="display:inline-block;"><label for="id_dente_3"><input type="checkbox" name="dente" value="15" placeholder="" class="form-control" id="id_dente_3" />
15</label>
</li>
<li style="display:inline-block;"><label for="id_dente_4"><input type="checkbox" name="dente" value="14" placeholder="" class="form-control" id="id_dente_4" />
14</label>
</li>
<li style="display:inline-block;"><label for="id_dente_5"><input type="checkbox" name="dente" value="13" placeholder="" class="form-control" id="id_dente_5" />
13</label>
</li>
<li style="display:inline-block;"><label for="id_dente_6"><input type="checkbox" name="dente" value="12" placeholder="" class="form-control" id="id_dente_6" />
12</label>
</li>
<li style="display:inline-block; margin-right:50px;"><label for="id_dente_7"><input type="checkbox" name="dente" value="11" placeholder="" class="form-control" id="id_dente_7" style="width: 21px;" />
11</label>
</li>
<li style="display:inline-block; width:20px;"><label for="id_dente_8"><input type="checkbox" name="dente" value="21" placeholder="" class="form-control" id="id_dente_8" style="width: 21px;"/>
21</label>
</li>
<li style="display:inline-block;"><label for="id_dente_9"><input type="checkbox" name="dente" value="22" placeholder="" class="form-control" id="id_dente_9" />
22</label>
</li>
<li style="display:inline-block;"><label for="id_dente_10"><input type="checkbox" name="dente" value="23" placeholder="" class="form-control" id="id_dente_10" />
23</label>
</li>
<li style="display:inline-block;"><label for="id_dente_11"><input type="checkbox" name="dente" value="24" placeholder="" class="form-control" id="id_dente_11" />
24</label>
</li>
<li style="display:inline-block;"><label for="id_dente_12"><input type="checkbox" name="dente" value="25" placeholder="" class="form-control" id="id_dente_12" />
25</label>
</li>
<li style="display:inline-block;"><label for="id_dente_13"><input type="checkbox" name="dente" value="26" placeholder="" class="form-control" id="id_dente_13" />
26</label>
</li>
<li style="display:inline-block;"><label for="id_dente_14"><input type="checkbox" name="dente" value="27" placeholder="" class="form-control" id="id_dente_14" />
27</label>
</li>
<li style="display:inline-block;"><label for="id_dente_15"><input type="checkbox" name="dente" value="28" placeholder="" class="form-control" id="id_dente_15" />
28</label>
</li>
<br><br><br>
<p style="color:red; font-style:italic; margin-top:-45px; font-size:20px;">Quadrante inferior: </p>
<hr class="check">
<br>
<p style="color:blue; font-style:italic; font-size:17px;">Esquerda:            Direita:</p>
<li style="display:inline-block;"><label for="id_dente_16"><input type="checkbox" name="dente" value="48" placeholder="" class="form-control" id="id_dente_16" />
48</label>
</li>
<li style="display:inline-block;"><label for="id_dente_17"><input type="checkbox" name="dente" value="47" placeholder="" class="form-control" id="id_dente_17" />
47</label>
</li>
<li style="display:inline-block;"><label for="id_dente_18"><input type="checkbox" name="dente" value="46" placeholder="" class="form-control" id="id_dente_18" />
46</label>
</li>
<li style="display:inline-block;"><label for="id_dente_19"><input type="checkbox" name="dente" value="45" placeholder="" class="form-control" id="id_dente_19" />
45</label>
</li>
<li style="display:inline-block;"><label for="id_dente_20"><input type="checkbox" name="dente" value="44" placeholder="" class="form-control" id="id_dente_20" />
44</label>
</li>
<li style="display:inline-block;"><label for="id_dente_21"><input type="checkbox" name="dente" value="43" placeholder="" class="form-control" id="id_dente_21" />
43</label>
</li>
<li style="display:inline-block;"><label for="id_dente_22"><input type="checkbox" name="dente" value="42" placeholder="" class="form-control" id="id_dente_22" />
42</label>
</li>
<li style="display:inline-block; margin-right:50px;"><label for="id_dente_23"><input type="checkbox" name="dente" value="41" placeholder="" class="form-control" id="id_dente_23" style="width:21px;"/>
41</label>
</li>
<li style="display:inline-block;"><label for="id_dente_24"><input type="checkbox" name="dente" value="31" placeholder="" class="form-control" id="id_dente_24" style="width:21px;"/>
31</label>
</li>
<li style="display:inline-block;"><label for="id_dente_25"><input type="checkbox" name="dente" value="32" placeholder="" class="form-control" id="id_dente_25" />
32</label>
</li>
<li style="display:inline-block;"><label for="id_dente_26"><input type="checkbox" name="dente" value="33" placeholder="" class="form-control" id="id_dente_26" />
33</label>
</li>
<li style="display:inline-block;"><label for="id_dente_27"><input type="checkbox" name="dente" value="34" placeholder="" class="form-control" id="id_dente_27" />
34</label>
</li>
<li style="display:inline-block;"><label for="id_dente_28"><input type="checkbox" name="dente" value="35" placeholder="" class="form-control" id="id_dente_28" />
35</label>
</li>
<li style="display:inline-block;"><label for="id_dente_29"><input type="checkbox" name="dente" value="36" placeholder="" class="form-control" id="id_dente_29" />
36</label>
</li>
<li style="display:inline-block;"><label for="id_dente_30"><input type="checkbox" name="dente" value="37" placeholder="" class="form-control" id="id_dente_30" />
37</label>
</li>
<li style="display:inline-block;"><label for="id_dente_31"><input type="checkbox" name="dente" value="38" placeholder="" class="form-control" id="id_dente_31" />
38</label>
</li>
</ul>
<div class="form-group">
<hr>
<label for="id_tipo">*Tipo de serviço:</label>
<input type="text" name="tipo" value=" " maxlength="100" placeholder="" class="form-control" required id="id_tipo" />
</div>
<div class="form-group">
<hr>
<label for="id_cor">Cor:</label>
<input type="text" name="cor" value=" " maxlength="5" placeholder="" class="form-control" required id="id_cor" />
</div>
<div class="form-group">
<hr>
<label for="id_escala">Escala:</label>
<input type="text" name="escala" value=" " maxlength="100" placeholder="" class="form-control" required id="id_escala" />
</div>
<div class="form-group">
<hr>
<label for="id_material">*Material:</label>
<select name="material" placeholder="" class="form-control" id="id_material">
<option value="Resina acrílica sobre estrutura em metal">Resina acrílica sobre estrutura em metal</option>
<option value="Resina composta sobre estrutura em zircônia">Resina composta sobre estrutura em zircônia</option>
<option value="Porcelana sobre estrutura em metal">Porcelana sobre estrutura em metal</option>
<option value="Porcelana sobre estrutura em zircônia">Porcelana sobre estrutura em zircônia</option>
<option value="Zircônia pura">Zircônia pura</option>
</select>
</div>
<div class="form-group">
<hr>
<label for="id_extra">Observações:</label>
<textarea name="extra" cols="40" rows="10" maxlength="500" placeholder="" class="form-control" id="id_extra">
</textarea>
</div>
<div class="form-group">
<hr>
<label>Preço inicial(em R$):</label>
<input type="number" name="preco" value="0" step="any" class="form-control" required id="id_preco" />
<!-- {% render_field form.preco class="form-control" placeholder=form.preco.label %}
{% for error in field.preco.errors %}
<span class="help-block">{{ error }}</span>
{% endfor %}
-->
</div>
<div class="form-group">
<hr>
<label for="id_prazo">Prazo(formato dd/mm/aaaa):</label>
<input type="text" name="prazo" value="" placeholder="" class="form-control" required id="id_prazo" /><input type="hidden" name="initial-prazo" value="2018-11-01" class="form-control" id="initial-id_prazo" />
</div>
</div>
<p style="color:red;">* Campos obrigatórios</p>
<button class="btn btn-primary btn-block" type="submit" name="" style="width:80px; float:right; margin-top:20px;">ENVIAR </button>
</form>
<br><br><br><br>
<a href="{% url 'lista-pregoes' user.id %}"><p><i class="fas fa-chevron-left"></i> Voltar</p></a>
</div>
</div>
{% endblock %}