Django query single underscore behaving like double underscore?
Those two fields just happen to both exist.
foreign_key_id
is an automatically created column on the MyModel
object, whereas foreign_key__id
is the ID on the foreign key table itself.
These values would both be the same..
MyModel1.foreign_key_id == 5 # this is stored on the model
# and does not require a lookup.
MyModel1.foreign_key.id == 5 # this is stored on the target table
# and requires a DB hit.