Reputation: 27
I'm trying to make a query to the Preferences table I have in django, but whenever I try to do a lookup to find a users entry, it just gives me this error.
ValueError: invalid literal for int() with base 10: 'jason'
The lookup I'm doing is this.
Preferences.objects.filter(customer='jason')
I can do this though which is odd.
Preferences.objects.all()
And I retrieve the query set of the one object I want. When I ask
Preferences.objects.all()[0].customer
And here I do retrieve the string 'Jason'. Can you explain what's going wrong either in my query or in the code? Any help would be appreciated and I can give other parts of code if needed!
#models.py
class Preferences(models.Model):
customer = models.OneToOneField(User, on_delete=models.CASCADE)
ebay_token = models.TextField(max_length=1024)
app_id = models.CharField(max_length=128, default='asdf', editable=False)
dev_id = models.CharField(max_length=128, default='1234', editable=False)
cert_id = models.CharField(max_length=128, default='1234', editable=False)
#this might need to be correct. I'm not sure if the user should have this much control over markup
markup = models.FloatField(max_length=3, validators=[MaxValueValidator(50, message='Can\'t be this high!'), MinValueValidator(1, message='Can\'t be this low!')])
seller_location = models.CharField(max_length=256)
#the ebay site number might need editing
ebay_site_number = models.IntegerField()
quantity = models.IntegerField(validators=[MinValueValidator(1, message='Must be atleast 1'), MaxValueValidator(10, message='Must be equal to or smaller than 10')])
#this will def need fixing here
fullfillment_policy = models.CharField(max_length=64)
payment_policy = models.CharField(max_length=64)
return_policy = models.CharField(max_length=64)
#default weight
default_weight = models.IntegerField(help_text='Default weight for item in pounds', default=15, validators=[MinValueValidator(1, message='Must be atleast 1 pound'), MaxValueValidator(500, message='Must be equal to or less than 500')])
paypalEmailAddress = models.CharField(max_length=128, default='[email protected]')
def __str__(self):
return "{} | Preferences".format(self.customer.username)
Upvotes: 2
Views: 1250
Reputation: 59274
models.OneToOneField
expects an id
for pk or a User
object.
Try
Preferences.objects.filter(customer__name='Jason')
or change the __name
part to whatever the field is in your User
model.
Upvotes: 3