1π
β
A user belongs to a department when he inserts a patient as author then this patient belongs to that department.
So letβs get the department
of a given user
first:
user = request.user # the doctor, the nurse etc
department = Institution.objects.get(user=user).department
Now you want all patients (Demographic
instances) where author.institution.department = department
patients = Demographic.objects.filter(author__institution__department=department)
π€bakkal
1π
I assume author
is a kind of caretaker attached to the patient. Then you can do a filter
on the userβs department:
department = Institution.objects.get(user=request.user).department
demographic = Demographic.objects.filter(patient_id=id).filter(author__institution__department=department)
π€Moses Koledoye
- [Answered ]-How to give {% url '' %} to a variable?
- [Answered ]-Django what variables available in a template .html file?
- [Answered ]-Django "lazy query execution" principle
Source:stackexchange.com