[Answered ]-Django: How to filter patients from one department?

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)

Leave a comment