Logical or of Django many to many queries returns duplicate results

后端 未结 1 1429
太阳男子
太阳男子 2020-12-30 05:12

I have models with many to many relationships like this:

class Contact(models.Model):
    name = models.TextField()
    address = models.TextField()

class M         


        
1条回答
  •  孤城傲影
    2020-12-30 05:21

    As SQL returns all matching records, Django dutifully maps them to objects. What you're looking for is the .distinct() queryset method that makes SQL collapse all duplicate rows into one.

    0 讨论(0)
提交回复
热议问题