首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >django db查询,获取错误

django db查询,获取错误
EN

Stack Overflow用户
提问于 2013-11-04 21:21:31
回答 1查看 55关注 0票数 0

这是我的模型:

代码语言:javascript
运行
复制
 class company_profile(models.Model):
       user=models.ForeignKey(User, unique=True)
       company=models.CharField(max_length=200)

      def __unicode__(self):
            return self.company

当我得到django shell时,我做了以下操作,它正确地工作了:

代码语言:javascript
运行
复制
  from my_app.models import company_profile
  everything = company_profile.objects.all()
  # this gives me the correct out put of the existing company names , 

但当我做以下事情时:

代码语言:javascript
运行
复制
  username = company_profile.objects.all().filer(user='rakesh')

  this is the error , that i am getting : 

  ValueError: invalid literal for int() with base 10: 'rakesh'

我如何解决这个问题,或者我的查询是错误的。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2013-11-04 21:23:16

你的问题是错的。user="rakesh"子句需要获取User实例的User实例或PK。

您可能指的是filter(user__username='rakesh')或其他什么,这取决于您在User上有哪些字段。

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

https://stackoverflow.com/questions/19777368

复制
相关文章

相似问题

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