On PostgreSQL only, you can pass positional arguments (*fields) in order to specify the names of fields to which the DISTINCT should apply...
When you specify field names, you must provide an order_by() in the QuerySet, and the fields in order_by() must start with the fields in distinct(), in the same order.
要在筛选中引用模型字段,可以使用Django ORM
F
函数:https://docs.djangoproject.com/en/dev/topics/db/queries/#filters-can-reference-fields-on-the-model但是我想你不能删除其中的一个
更新
当你像
Object.objects.filter(photo__name='something')
那样过滤时,你会根据相关的照片名过滤对象表。所以你要处理两张桌子的连接。如果要排除名为“相关照片名”的对象,应执行以下操作这有用吗?
如果您使用的是PostgreSQL,请查看Django docs on ^{} :
因此,在您的示例中,可以使用以下方法删除某些字段上的重复项:
相关问题 更多 >
编程相关推荐