我有這樣一個模型下面過濾器在查詢集獨特的記錄基於模型場在Django
class SafetyRead(models.Model):
name = models.CharField(max_length=256)
accession_number = models.CharField(max_length=256)
data = models.CharField(max_length=256)
approved = models.BooleanField()
radiologist = models.BooleanField()
def __unicode__(self):
return 'SafetyRead - %s'%self.accession_number
通常當我在下面的方式,我得到的結果
查詢進行搜索
SafetyRead.objects.filter(approved=False,radiologist=False)
結果
[<SafetyRead: SafetyRead - 2983>, <SafetyRead: SafetyRead- 2582>, <SafetyRead: SafetyRead - 2583>, <SafetyRead: SafetyRead - 2522>, <SafetyRead: SafetyRead - 2522>]
正如你可以從上面的查詢觀察結果中的最後兩個記錄被複制與現場accession_number
即2522
所以我想根據喜歡同樣的查詢集格式字段accession_number
過濾獨特SafetyRead對象記錄(刪除重複的accession_number 2522記錄後)
[<SafetyRead: SafetyRead - 2983>, <SafetyRead: SafetyRead- 2582>, <SafetyRead: SafetyRead - 2583>, <SafetyRead: SafetyRead - 2522]
那麼如何過濾呢?
從你想離開這兩個重複的記錄呢?那個更大的ID? – 2014-09-02 08:38:33