I'm using django v1.8.
I extended the existing User model.
user = models.OneToOneField(User, on_delete=models.CASCADE)
department = models.CharField(max_length=100)
patient_id = models.IntegerField(unique= True ,primary_key=True)
pub_date = models.DateTimeField(auto_now=True)
author = models.ForeignKey(User)
history = HistoricalRecords()
patient = Demographic.objects.filter(patient_id__icontains=id)
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 = request.user # the doctor, the nurse etc department = Institution.objects.filter(user=user).first().department
Now you want all patients (
Demographic instances) where
author.institution.department = department
patients = Demographic.objects.filter(author__institution__department=department)