我有以下型号:
class MyModel(models.Model):
first_name = models.CharField(max_length=255)
class MyOtherModel(models.Model):
model = models.ForeignKey(MyModel)
我有一个MyModelid 列表:[1, 2, 3, 5, 7, 11]. 仅[1, 2, 3]在MyOtherModel.
MyOtherModel根据该 ID 列表进行过滤的最佳方法是什么?我尝试执行以下操作:MyOtherModel.objects.filter(model__id__in=ids)但它没有返回任何内容,因为5, 7, 11找不到。
编辑:错字。