[Django]-Django: Why don't foreign key lookups automatically use the pk?

1👍

In the second case, you are comparing objects. And, from Django documentation, in order to compare an object you have to use the == operator.

On top of that: why don’t you use ach.alias_set.objects.count(), as explained in the query section of the manual?

👤rob

2👍

I can’t answer why the design decision was made to implement it this way, but most likely its to follow the Python philosophy that things should be specified explicitly and not implied.

The reason it doesn’t work is because __contains expects a field to reference. The bit you passed it was a reference to a whole object.

Leave a comment