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

Popular posts from this blog

linux - Using a Cron Job to check if my mod_wsgi / apache server is running and restart -

actionscript 3 - TweenLite does not work with object -

jQuery Ajax Render Fragments OR Whole Page -