In Django, you can make database queries like the following:
Model.objects.filter(name__icontains = 'bob')
The question is: how is this working ‘under the cover’? Is the double underscore a Django thing or a Python thing? Is this just a single variable named name__icontains, or is it some sort of attribute-access syntax? In the former case, how does the filter method parse the variable name to determine that you are searching the Model table for a name that contains somewhere the string bob?
It’s a Django thing, implemented with some Python things.
In Python, you can get a dictionary of the keyword arguments passed to a function or method:
From there, it can simply iterate over the dictionary keys and split them on
__, and then interpret it however it wants. In this case, it takes the last part and interpretsicontainsas case-insensitive contains.