based on multiple choice field i want to show result in template but I have no idea how to do as you can see in this model i give lunch choice to students base on lunch choice i want to show result but it is not working for ex if he select sandwich the result after submit will you sandwich will be ready and same for others
from multiselectfield import MultiSelectField
class student(models.Model):
lunch_choice = [
('Sandwich', 'Sandwich'),
('Salad', 'Salad'),
('omlete', 'omlete'),
]
name = models.CharField(max_length=70, blank=False)
classs = models.CharField(max_length70, blank=True)
lunch = MultiSelectField(choices=lunch_choice, blank=True)
def __str__(self):
return self.name
i tried in my HTML and it didn't work
{% if student.classs %}
{% if student.lunch == 'Sandwich' %}
<p> your sandwich will be ready</p>
{% endif %}
{%endif%}
and in form.py using widget
widgets = {
'lunch':forms.CheckboxSelectMultiple(attrs={'id':'lunch'}),
}
my views.py
def preview(request):
student = student.objects.all()
return render(request, 'preview.html',{'student':student})
