首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >基数为10的int()的文本无效:'John Doe‘

基数为10的int()的文本无效:'John Doe‘
EN

Stack Overflow用户
提问于 2015-06-01 20:37:44
回答 1查看 613关注 0票数 0

我有一个模型患者和另一个检查,现在我想根据名称检索患者的检查,但我遇到了错误int()的无效文本,基数为10:'John Doe‘

代码语言:javascript
复制
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

这是我的观点

代码语言:javascript
复制
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)

模型考试

代码语言:javascript
复制
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

针对患者的模型

代码语言:javascript
复制
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)
EN

回答 1

Stack Overflow用户

发布于 2015-06-01 20:49:10

更改查询

代码语言:javascript
复制
exam = Test.objects.filter(patient__user__exact=name)

代码语言:javascript
复制
exam = Test.objects.filter(patient__user__name__exact=name)
#------------------------------------------^

请注意添加的user__name。在这里,我假设您的MyUser类具有您想要比较的属性name

在查询中,您试图将字符串name与对象user (或者更确切地说,该对象的内部id )进行比较,这是不兼容的。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/30573680

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档