class PatientDetailView(TemplateView):
template_name = 'detail_view.html'
def get_context_data(self, **kwargs):
context = super().get_context_data(**kwargs)
vitals_list = DailyVitals.objects.get(patient = )
context['vitals_list'] = vitals_list
return context
What query should I pass to filter queryset with the patient's username?
urls.py:
urlpatterns = [
path('home/', HomeView.as_view(), name='home'),
path('', HomeView.as_view(), name='home'),
path('addRecord/', VitalCreateView.as_view(), name='create_record'),
path('detail/<str:username>', PatientDetailView.as_view(), name='detail'),
path('doctor', DoctorView.as_view(), name='doctor'),
path('patient', PatientView.as_view(), name='patient'),
]
models.py
class User(AbstractUser):
is_doctor = models.BooleanField('doctor status', default=False)
is_patient = models.BooleanField('patient status', default=False)
class Doctor(models.Model):
user = models.OneToOneField(User, on_delete=models.CASCADE, primary_key=True)
def __str__(self):
return self.user.username
class Patient(models.Model):
user = models.OneToOneField(User, on_delete=models.CASCADE, primary_key=True)
doctor = models.ForeignKey(Doctor, on_delete=models.CASCADE, null=True, blank=True)
def __str__(self):
return self.user.username
class DailyVitals(models.Model):
patient = models.ForeignKey(Patient, on_delete=models.CASCADE, null=True, blank=True)
date = models.DateField(auto_now_add=True)
blood_pressure = models.IntegerField()
sugar_level = models.IntegerField()
temperature = models.IntegerField()
weight = models.IntegerField()
def __str__(self):
return str(self.date)
def get_absolute_url(self):
return reverse("patient")
I tried to pass <a href= {% url 'detail' i.patient.user.username %}> from the template but I get this error "
Reverse for 'detail' with arguments '('',)' not found. 1 pattern(s) tried: ['detail/(?P[^/]+)\Z']:
Thanks