繁体   English   中英

django db查询,出现错误

[英]django db query, getting error

这是我的模特:

 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时,我做了以下工作,它工作正常:

  from my_app.models import company_profile
  everything = company_profile.objects.all()
  # this gives me the correct out put of the existing company names , 

但是当我执行以下操作时:

  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'

我该如何解决,还是我的查询错误。

您的查询是错误的。 user="rakesh"条款需要得到无论是User实例或PK的User实例。

您可能是指filter(user__username='rakesh')东西,具体取决于您对User拥有哪些字段。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM