Django: filtering models on the difference of Counts of related models -
I've got a bunch of order objects, each one or more orderreaves are associated with objects (as their reverse relation Appearance order.order_oroz.all ()) with parent order.
Each order has a collection_states attribute, which can be 'collected', 'recalls' or a bunch of other special values. Each order has a status attribute, one of the valid values for 'processing'.
I'm on the loss in trying to create an order query set which lists the following objects Criteria: The status of the order is 'processing', its archive_stateus = 'calculation' calculated * < / Code> Orders are less than the total number of their orders
To keep it explicit:
Order with two rows, both 'unlocked': included in the QS- order With three rows, one 'collected', two 'Ricolte' 'Include: QS
order with two lines, both "collect": QS not included!
(You can replace 'unselected' with any other value which is not 'collected' and the criteria still is the same, it 'collected' vs. any other collection_stats).
I did as far as the order was given. Object. Filters (status_exact = 'processing'), but besides this, annotations, Q () objects etc. have failed miserably in all my efforts.
I read your question again at least 30 times. Let me see that I understand what you want.
This will not work because no order order will be made with crawling_states == 'collected'
order
something else Try
Order = Order. Objects (order- 'processing'). Exit (order_row__collection_status = 'collected')
in order for the filter (condition = 'processing') arr = []: col = order.order_rows.filter (collection_status = 'collected') if the col.count ( ) & Lt; Order.order_rows.all () Count (): arr.append (order.pk) order = orders.filter (pk__in = arr)
to just clear
its archive_Status = 'Assembled' orderers are less than the total number of your orders
After reading your question for a 31st time, it seems that the total number of OrderRows is always in any order > Can be> = 'collected' number of orderers
Should an order with 29 rows, 14 are collected and 15 others should be included? What are the orders with 29 rows, 15 collected and 14 other?
Comments
Post a Comment