Advertisement
Guest User

Untitled

a guest
Mar 31st, 2020
118
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.53 KB | None | 0 0
  1. debt_import_record_system_status_qs = DebtImportRecordSystemStatus.objects.all()
  2.  
  3. last_system_statuses_qs = debt_import_record_system_status_qs.filter(import_record_id=OuterRef('pk')).order_by('-date_created')
  4. all_unregistered_records_with_last_ss_qs = all_unregistered_records_qs.annotate(last_record_system_status=Subquery(last_system_statuses_qs.values('status')[:1]))
  5.  
  6. rejected_records = all_unregistered_records_with_last_ss_qs.aggregate(
  7.     count_records_of_rejected=Count('id', filter=Q(last_record_system_status='rejected'))
  8. )
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement