Reputation:
In django, why does it not allow:
ItemInstance.objects.filter(provider_id__icontains='sting'))
But it does allow:
ItemInstance.objects.filter(provider__name__icontains='sting'))
provider_id
and provider__name
would give the same value, as the foreign key is to the name
field. Why doesn't it allow the first method of referencing it?
Upvotes: 0
Views: 92
Reputation: 9461
I suspect you're using a natural key as the primary key: you've got primary=True
on the name field? If so use this:
ItemInstance.objects.filter(provider_pk__icontains='sting'))
id
field is only present if you don't specify your primary key. Django accommodates this my providing pk
, which is a proxy for whatever field is your primary key
Upvotes: 1