Làm thế nào bạn có thể thực hiện phân loại phức tạp trên một đối tượng trước khi chuyển nó vào mẫu? Ví dụ: đây là chế độ xem của tôi:Sắp xếp và lập chỉ mục vào danh sách trong mẫu Django?
@login_required
def overview(request):
physicians = PhysicianGroup.objects.get(pk=physician_group).physicians
for physician in physicians.all():
physician.service_patients.order_by('bed__room__unit', 'bed__room__order', 'bed__order')
return render_to_response('hospitalists/overview.html', RequestContext(request, {'physicians': physicians,}))
Đối tượng bác sĩ không được đặt hàng đúng trong mẫu. Tại sao không?
Ngoài ra, làm cách nào để bạn lập chỉ mục vào danh sách bên trong mẫu? Ví dụ, (điều này không làm việc):
{% for note_type in note_types %}
<div><h3>{{ note_type }}</h3>
{% for notes in note_sets.index(parent.forloop.counter0) %}
#only want to display the notes of this note_type!
{% for note in notes %}
<p>{{ note }}</p>
{% endfor %}
{% endfor %}
</div>
{% endfor %}
Cảm ơn bó, Pete
@Peter Mortensen, tại sao bạn phải loại bỏ lòng biết ơn khỏi bài đăng của mọi người? Xem bản sửa đổi số 8 của câu hỏi này. Tôi không thấy điều này có thể chấp nhận được. – slypete