我试过了:
from django.db.models import F
MyObj.objects.filter(field1__contains=F('field2'))
它是空的,而以下确实给了我结果:
[o for o in MyObj.objects.all() if o.field1 and o.field2 in o.field1]
以下是模型定义:
class MyObj(models.Model):
field1 = models.CharField(max_length=100, blank=True, null=True)
field2 = models.CharField(max_length=2, choices=CHOICES, default='a', db_index=True)
用F
个对象做不到这个吗?