'Cannot query "sabbir": Must be "User" instance
I mean when a doctor uploads a file, the patients that are under that doctor can see that file. In the same way when a patient uploads his prescription only that doctor can see.
views.py
def practitioner_tab(request, practitioner_id):
client = Appointment.objects.get(id=practitioner_id)
practitioner = Profile.objects.get(user=client.practitioner)
notes = AddNote.objects.filter(user=client.practitioner)
appointments=Appointment.objects.filter(user=client.practitioner)
context = {
'client': client,
'practitioner': practitioner,
'notes': notes,
'appointments': appointments,
}
return render(request, 'client/practitioner_tab.html', context)
models.py
class Profile(models.Model):
phone = models.CharField(max_length=50, blank=True, null=True)
avatar = models.ImageField(max_length=50, blank=True, null=True,
upload_to='practitioner/avatar')
start_date = models.DateTimeField(auto_now_add=True)
user = models.OneToOneField(User, on_delete=models.CASCADE)
def __str__(self):
return self.user.username
class Appointment(models.Model):
Appointments = [
('audio', 'audio'),
('video', 'video'),
]
practitioner = models.ForeignKey(Profile,
on_delete=models.CASCADE, related_name='practitioner')
time = models.DateTimeField()
appointment = models.CharField(max_length=100,
choices=Appointments)
user = models.ForeignKey(User, on_delete=models.CASCADE)
def __str__(self):
return self.user.username
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
