django db查询,得到错误

rak*_*esh 0 python django django-models

这是我的模特:

 class company_profile(models.Model):
       user=models.ForeignKey(User, unique=True)
       company=models.CharField(max_length=200)

      def __unicode__(self):
            return self.company
Run Code Online (Sandbox Code Playgroud)

当我得到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 , 
Run Code Online (Sandbox Code Playgroud)

但是当我做以下事情时:

  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'
Run Code Online (Sandbox Code Playgroud)

我怎么能解决这个问题,或者我的查询错了.

Pet*_*per 5

你的查询错了.该user="rakesh"子句需要获取User实例或实例的PK User.

你可能意味着filter(user__username='rakesh')什么,取决于你所拥有的领域User.