Remove duplicates in a Django query

前端 未结 6 1186
北恋
北恋 2020-12-08 06:39

Is there a simple way to remove duplicates in the following basic query:

email_list = Emails.objects.order_by(\'email\')

I tried using

6条回答
  •  佛祖请我去吃肉
    2020-12-08 07:17

    I used the following to actually remove the duplicate entries from from the database, hopefully this helps someone else.

    adds = Address.objects.all()
    d = adds.distinct('latitude', 'longitude')
    for address in adds:    
      if i not in d:
        address.delete()
    

提交回复
热议问题