Django comparing model instances for equality

后端 未结 8 1766
夕颜
夕颜 2020-12-01 11:53

I understand that, with a singleton situation, you can perform such an operation as:

spam == eggs

and if spam and eggs

8条回答
  •  一生所求
    2020-12-01 12:16

    From Django documentation:

    To compare two model instances, just use the standard Python comparison operator, the double equals sign: ==. Behind the scenes, that compares the primary key values of two models.

提交回复
热议问题