Django comparing model instances for equality

后端 未结 8 1776
夕颜
夕颜 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:21

    Just for the record, comparing:

        spam == eggs
    

    is dangerous if there is any chance that either of them could be a deferred model instance created by Model.objects.raw() query or by .defer() applied to a 'normal' QuerySet.

    I put more details here: Django QuerySet .defer() problem - bug or feature?

提交回复
热议问题