I have a table in which I show an object of sight, these are vaccines, what I want is that, for example, if they already put that vaccine, I will not get the name of the vaccine, only the dates in those who got the vaccines.
template.html
<table width="100%" class="table-bordered">
<caption style="text-align: center; font-weight:bolder; font-size: 20px; color:black">Vacunas aplicadas</caption>
</td>
<td>Descripción</td>
<td>Fecha de aplicación</td>
<td>Nota</td>
</tr>
{% for vaccine in preventive %}
<tr>
<td>{{ forloop.counter }}</td>
<td>{{ vaccine.vaccines }}</td>
<td>{{ vaccine.vaccine_date }}</td>
<td>{{ vaccine.vaccine_note}}</td>
{% ifchanged vaccine.vaccines%}
</tr>
{% endfor %}
view.py
class PreventiveMedicineView(FormView):
template_name = 'clipboard_medicinapreventiva.html'
form_class = PrevMedicineForm
def form_valid(self, form, **kwargs):
vac = self.request.POST['description']
vaccines = Vaccines.objects.get(description=vac)
vaccine_date = self.request.POST['vaccine_date']
vaccine_note = self.request.POST['vaccine_note']
if not vaccine_date:
vaccine_date=datetime.datetime.now().date()
patient=Patient.objects.get(pk=self.kwargs['id'])
clipboard_patient = Clipboard.objects.get(patient=patient)
prev_medicine = PreventiveMedicine(clipboard=clipboard_patient,
vaccines=vaccines,
vaccine_date=vaccine_date,
vaccine_note=vaccine_note)
prev_medicine.save()
success_url = reverse('preventive_medicine', kwargs={'id': patient.pk} )
return HttpResponseRedirect(success_url)
def form_invalid(self, form, **kwargs):
print form._errors
return self.render_to_response(self.get_context_data(form=form))
def get_context_data(self, **kwargs):
context = super(PreventiveMedicineView, self).get_context_data(**kwargs)
context.update({
'patient': Patient.objects.get(pk=self.kwargs['id']),
'prev_medicine': PreventiveMedicine.objects.all(),
'vaccines': Vaccines.objects.all(),
'preventive': PreventiveMedicine.objects.filter(clipboard__patient=self.kwargs['id'])
})
return context
For example this form
shows them to me like this:
tetanos--2016-01-02--test
tetanos--2015-10-03--descripcion.
H1N1 --2016-09-11--observaciones
hepatitis-2016-08-01--C
Well, as I said above, what I want is that in the previous example, I'll show it to me like this
TETANOS
--2016-01-02--test.
--2015-10-03--descripcion.
H1N1 --2016-09-11--observaciones
hepatitis-2016-08-01--C