Django-CHOICE DDL-隐藏/禁用选择

时间:2019-05-11 17:18:52

标签: django hide choice disable

在我的模型中,我定义了Choice DDL对象:

a = '900'
b = '915'
c = '930'
d = '945'
e = '1000'
f = '1015'
g = '1030'
h = '1045'
i = '1100'
l = '1115'
m = '1130'
n = '1145'
z = 'è uguale'

ORARI_CHOICES = (
    (z, "Indifferente"),
    (a, "09.00"),
    (b, "09.15"),
    (c, "09.30"),
    (d, "09.45"),
    (e, "10.00"),
    (f, "10.15"),
    (g, "10.30"),
    (h, "10.45"),
    (i, "11.00"),
    (l, "11.15"),
    (m, "11.30"),
    (n, "11.45"),
)

fasce_orarie = models.CharField(max_length=15, choices=ORARI_CHOICES, default=000)

在模板中,我可以按照以下方式显示DDL:

{{ form.fasce_orarie }}

我很难确定如何在旅途中禁用某些特定选择字段。

我能够通过从视图传递变量来禁用其他表单字段到模板,例如:

if request.method == 'GET':
    return render(request, "prenota.html", {'form': form, 'free_places': free_places})
else:
    form = PrenotaForm(request.POST)

,然后在模板中

{% if free_places > 0 %}
      {{ form.field_name }}
{% endif %}

任何提示我如何只能隐藏/禁用某些DDL选择?还是单选按钮?

或者可能是问题在于如何以更基本的方式呈现DDL,以便我可以处理它?<​​/ p>

0 个答案:

没有答案