Changes between Initial Version and Version 1 of Ticket #30769
- Timestamp:
- Sep 10, 2019, 10:22:25 AM (5 years ago)
Legend:
- Unmodified
- Added
- Removed
- Modified
-
Ticket #30769 – Description
initial v1 69 69 Code which leads to the error 70 70 {{{ 71 72 73 74 75 76 71 # Base Query Construct 72 auth_query = UserAuth.objects.filter(user_id=OuterRef('user_id')).order_by( 73 '-received_at')[:1] 74 base_employees = ( 75 base_employees.annotate(auth_received_at=Subquery(auth_query.values('received_at')), 76 auth_response=Subquery(auth_query.values('response')))) 77 77 78 # Q object building 79 q = Q() 80 if IS_AUTH_REJECTED in auth_status: 81 q |= Q(auth_response__REJECTED='N') 78 79 # Q object building 80 q = Q() 81 if IS_AUTH_REJECTED in auth_status: 82 q |= Q(auth_response__REJECTED='N') 82 83 83 84 base_employees.filter(q) … … 86 87 Workaround 87 88 {{{ 88 89 90 91 89 # base query construct 90 auth_query = UserAuth.objects.annotate( 91 has_access=KeyTextTransform('REJECTED', 'response') 92 ).filter(user_id=OuterRef('user_id')).order_by('-received_at')[:1] 92 93 93 94 95 94 base_employees = base_employees.annotate( 95 auth_received_at=Subquery(auth_query.values('received_at')), 96 has_access=Subquery(auth_query.values('has_access'), output_field=CharField())) 96 97 97 98 99 100 98 # q object creation 99 q = Q() 100 if IS_AUTH_REJECTED in auth_status: 101 q |= Q(has_access='N') 101 102 102 103 base_employees.filter(q) 103 104 104 105 }}}