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.
- [Django]-How to separate models in different modules in Django admin's index?
- [Django]-What's the best way to handle different forms from a single page in Django?
- [Django]-Django send_mail returns SMTPConnectError
- [Django]-Loop through a defaultdict(list) structure in a django template
- [Django]-Why does this Django test pass?
Source:stackexchange.com