2016-03-26 4 views
0

Ich möchte überprüfen, ob chron_id vorhanden ist und Zeilen ohne Duplikate erhalten. Wenn chron_id Null ist, dann alle Zeilen holen.Kombinieren Django Filter

toponymies_one = Toponymy.objects.filter(chron_id__isnull=False).distinct('chron_id') 
toponymies_two = Toponymy.objects.filter(chron_id__isnull=True) 

Sollte ich diese beiden Abfrage-Sets zusammenführen? Gibt es einen besseren Weg, es zu tun?

| id | somevalue | somevalue | chron_id | 
|----|-----------|-----------|----------| 
| 1 | foo  | foo  |   | # I want this row 
| 2 | bar  | foo  | 2  | 
| 3 | foo  | bar  |   | # I want this row 
| 4 | foo  | foo  |   | # I want this row 
| 5 | bar  | foo  | 5  | 
| 6 | foo  | bar  |   | # I want this row 
| 7 | foo  | foo  |   | # I want this row 
| 8 | bar  | foo  | 5  | # I want this row 
| 9 | foo  | bar  | 2  | # I want this row 

Dank ...

Antwort