Django complex query which may need union -
i try complex query in django through these models.
class jobtitlestatus(): pending = 0 confirmed = 1 banned class employer(models.model): name = models.charfield(max_length=1000) isvalidated = models.booleanfield(null=false) eminence = models.integerfield(blank=false,null=false,default=4) class jobtitle(models.model) name = models.charfield(max_length=1000) employer = models.foreignkey(employer,null=true,blank=true) status = models.integerfield(null=false, choices=jobtitlestatus) i try list validated employers depending on size of confirmed jobtitles. if there no conmfirmed jobtitle of employer should @ end of list.
i try
elist = employer.objects.filter(name__icontains=emp).filter(isvalidated=true) elist.filter(jobtitle__status=jobtitlestatus.confirmed).annotate(jtt_count=count('jobtitle')).order_by('-jtt_count','eminence') this query want more or less however, expect, employers doesn't have confirmed job titles eliminated.
how can add employers @ end of query efficiently ?
thanks
elist.annotate(jtt_count=count('jobtitle')).order_by('jobtitle__status','-jtt_count','eminence') should work, think.
Comments
Post a Comment