Order mnt_by without duplicates

master
Sebastian Lohff 7 years ago
parent 1c95b05e8b
commit f25d07ccf7

@ -1,9 +1,10 @@
from django import forms
from django.db.models import Case, When, IntegerField
from django.db.models import Q
from .models import Maintainer, Contact, InetNum, ASBlock, ASNumber
from .validators import HandleValidatorWithSuffix, IP46CIDRValidator
from .formfields import MultiTextInput
from .helpers import orderQueryset
import ipaddress

@ -1,7 +1,7 @@
import whoisdb.models
import domains.models
from django.db.models import F
from django.db.models import F, When, Max, Case, IntegerField
import ipaddress
import re
@ -150,3 +150,16 @@ def findHandleFromStr(rawValue):
pass
return None
def orderQueryset(qs, userOwned, objOwned):
# when for
whens = [When(userOwned, then=2)]
if objOwned:
# add existing
whens.append(When(objOwned, then=1))
qs = qs.annotate(card=Max(Case(*whens, default=0, output_field=IntegerField()))).order_by("-card")
return qs

Loading…
Cancel
Save