i have a model patient and another one exam, now i want to retrieve patient's exams based on the name, but i am stuccoed with the error invalid literal for int() with base 10: 'John Doe'
ValueError at /labtech/John Doe/see_exam
invalid literal for int() with base 10: 'John Doe'
Request Method: GET
Request URL: http://homasoft.com:8000/labtech/John%20Doe/see_exam
Django Version: 1.8
Exception Type: ValueError
Exception Value:
invalid literal for int() with base 10: 'John Doe'
Exception Location: /Library/Python/2.7/site- packages/django/db/models/fields/__init__.py in get_prep_value, line 985
Python Executable: /usr/bin/python
Python Version: 2.7.5
Python Path:
['/Users/mymacbookpro/Documents/Virtualenvs/hospital/src',
'/Library/Python/2.7/site-packages/pip-1.4.1-py2.7.egg',
'/Users/mymacbookpro/Documents/Virtualenvs/hospital/src',
'/Users/mymacbookpro/Documents/Virtualenvs/hospital/src/django-social-auth',
'/Users/mymacbookpro/Documents/Virtualenvs/hospital/src/django-socialprofile',
'/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python27.zip',
'/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7',
'/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat- darwin',
'/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-mac',
'/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-mac/lib-scriptpackages',
'/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python',
'/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-tk',
'/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-old',
'/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-dynload',
'/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/PyObjC',
'/Library/Python/2.7/site-packages']
Server time: Mon, 1 Jun 2015 12:27:27 +0000
here is my view
def see_exam(request, name):
exam = Test.objects.filter(patient__user__exact=name)
context = {
'exam' : exam
}
return render(request, 'account/labtechs/see_results.html', context)
model exam
class Test(models.Model):
exam = models.ForeignKey(Exam)
patient = models.ForeignKey(Patient)
date = models.DateField()
result = models.TextField(default="negative")
done_by = models.CharField(max_length=120)
def __unicode__(self):
return self.exam.name
model for patient
class Patient(models.Model):
"""docstring for Patient"""
user = models.OneToOneField(MyUser)
date_of_birth = models.DateTimeField(blank=True, null=True)
age = models.IntegerField(default=1)
sex = models.OneToOneField(Sex)
religion = models.CharField(max_length=120, blank=True, null=True)
village = models.CharField(max_length=120)
status = models.OneToOneField(Status, blank=True, null=True)
relative = models.CharField(max_length=120)
phone = models.IntegerField(default=1)
allergies = models.TextField(default="", blank=True, null=True)
defficiencies = models.TextField(default="", blank=True, null=True)
created_at = models.DateTimeField(auto_now=True)
updated_at = models.DateTimeField(auto_now_add=True)
def __unicode__(self):
return "%s %s" %(self.user.first_name, self.user.last_name)