1

I need to filter null and blank fields for several attributes. So far the solution I have found that works is this one :

avaluos=Avaluo.objects.filter(Q(Estatus='CONCLUIDO',Pagado=False,Factura__isnull=True)
|Q(Estatus='CONCLUIDO',Factura__isnull=True,Pagado__isnull=True)
|Q(Estatus='CONCLUIDO',Factura__exact='',Pagado__isnull=True)
|Q(Estatus= 'CONCLUIDO',Factura__exact='',Pagado=False))

However I am pretty sure this is not the best option. Is there any more efficient way to do this?

1 Answer 1

2

I think if you chain your clauses, it'll be more readable.

avaluos= ( Avaluo.objects
           .filter(Estatus='CONCLUIDO')
           .filter(Q(Factura='')|Q(Factura__isnull=True))
           .filter(Q(Pagado=False)|Q(Pagado__isnull=True)) )
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.