python - Django display data in a table -- Sort of a table within a table (nested forloop?). Data needs to link as well -
i'm not sure best way explain created example picture , made data:
i looked @ post , know need use forloop template stuff: displaying table in django database
the parts throwing me off how have table within table. example, doctor 'bob" has 3 different patients. bob has 1 row bob's patient column has 3 rows within it.
<table class="table table-striped table-bordered"> <thead> <th>name</th> <th>total patient meetings</th> <th>patient</th> <th>meetings patient</th> </thread> <tbody> {% doctor in query_results %} <tr> <td> {{ doctor.name }} </td> <td> {{ doctor.total_meetings }}</td> //*would have nested forloop in here?*// {% patient in query_results2 %} <td> {{patient.name }} </td> <td> {{patient.meeting_number }}</td> {% endfor %} </tr> {% endfor %} </tbody> </table> i'm having trouble finding example work off of , not sure how approach it.
i need patients link individual patient pages. if click on bob's patient 'c755' directed patient's page. thinking like:
`<p><a href="patient/{{patient.name}}">{{patient.name}}:</a></p>` thanks help. not sure best way approach this.
"a 'related manager' manager used in one-to-many or many-to-many related context." https://docs.djangoproject.com/en/1.10/ref/models/relations/
i can't see how relation between doctor , patient is, supposing this:
class patient(models.model): name = models.charfield(max_length=50) class doctor(models.model): patient = models.manytomanyfield(patient, verbose_name='patients') you can easly iterate on doctor.patient using:
{% doctor in doctors %} {% patient in doctor.patients.all %} {{ patient.name }} {% endfor %} {% endfor %} if don't have verbose_name attribute relation, instead of using doctor.patients.all use doctor.patients_set.all.
and patient's page, can use method inside class patient easly this:
<a href="{{ patient.get_absolute_url }}">{{ patient.name }}</a> "with get_absolute_url on model can make dealing them on per-object basis simpler , cleaner across entire site"

Comments
Post a Comment