here is my model :
class company_profile(models.Model):
user=models.ForeignKey(User, unique=True)
company=models.CharField(max_length=200)
def __unicode__(self):
return self.company
and when i got django shell i did the following, it worked correctly :
from my_app.models import company_profile
everything = company_profile.objects.all()
# this gives me the correct out put of the existing company names ,
but when i do the following :
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'
how can i solve this , or is my query wrong.
Your query is wrong. The user="rakesh"
clause needs to get either a User
instance or the PK of a User
instance.
You may mean filter(user__username='rakesh')
or something, depending on what fields you have on User
.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.