这是我的模型:
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'我如何解决这个问题,或者我的查询是错误的。
发布于 2013-11-04 21:23:16
你的问题是错的。user="rakesh"子句需要获取User实例的User实例或PK。
您可能指的是filter(user__username='rakesh')或其他什么,这取决于您在User上有哪些字段。
https://stackoverflow.com/questions/19777368
复制相似问题