In my model I define a Choice DDL object:

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)

In the template I was able to display the DDL al follow:

{{ form.fasce_orarie }}

I'm having hard times figuring out how could I disable certain specific choice fields on the go.

I was able to disable other form fields into the template, by passing a variable from the view, for example:

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

and then in the template

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

Any hint how could I hide/disable only a certain DDL choice? Or radio button?

Or may be the question is how to render a DDL in a more basic way so I can handle it?

0 Answers