assume that i have a list of dictionaries
get_all_item
[
"id": 1,
"user_payment_id": 2,
"user_id": 1,
"email": "string",
"order_number": 53010,
"billing_first_name": "string",
"billing_last_name": "string",
"billing_phone_number": "string",
"billing_country": "string",
},
{
"id": 2,
"user_payment_id": 2,
"user_id": 1,
"email": "string",
"order_number": 53010,
"billing_first_name": "string",
"billing_last_name": "string",
"billing_phone_number": "string",
"billing_country": "string",
},
{
"id": 3,
"user_payment_id": 2,
"user_id": 1,
"email": "string",
"order_number": 53010,
"billing_first_name": "string",
"billing_last_name": "string",
"billing_phone_number": "string",
"billing_country": "string",
]
i want to filter the "order_number": 53010 match item from list and make another list of dictionaries of match item
> i want to make a list like this:
get_all_item
[
"id": 1,
"user_payment_id": 2,
"user_id": 1,
"name": "string",
"email": "string",
"order_number": 53010 [
{
"item_id": 1,
"item_name": "string",
"item_price": 0,
"item_description": "string"
},
{
"item_id": 2,
"item_name": "string",
"item_price": 0,
"item_description": "string"
},
{
"item_id": 3,
"item_name": "string",
"item_price": 0,
"item_description": "string"
}
]
"product_is_active": true,
"billing_first_name": "string",
"billing_last_name": "string",
"billing_phone_number": "string",
"billing_country": "string"
}
]
i want the result of matching order number in another list. I have tried find the row from the list
def get_all_checkout_items(db: Session):
data = db.execute(f'SELECT ROW_NUMBER() OVER (ORDER BY 1) AS id,public."tbl_order_and_payment-order".id user_payment_id,public."tbl_order_and_payment-order".user_id user_id,public."tbl_order_and_payment-order".email email,public."tbl_order_and_payment-order".order_id order_number,public."tbl_order_and_payment-order".billing_first_name billing_first_name,public."tbl_order_and_payment-order".billing_last_name billing_last_name,public."tbl_order_and_payment-order".billing_phone_number billing_phone_number,public."tbl_order_and_payment-order".billing_country billing_country ,public."tbl_order_and_payment-order".billing_division billing_division ,public."tbl_order_and_payment-order".billing_district billing_district ,public."tbl_order_and_payment-order".billing_address billing_address ,public."tbl_order_and_payment-order".billing_police_station billing_police_station ,public."tbl_order_and_payment-order".billing_post_code billing_post_code ,public."tbl_order_and_payment-order".shipping_first_name shipping_first_name,public."tbl_order_and_payment-order".shipping_last_name shipping_last_name,public."tbl_order_and_payment-order".shipping_phone_number shipping_phone_number,public."tbl_order_and_payment-order".shipping_country shipping_country,public."tbl_order_and_payment-order".shipping_division shipping_division,public."tbl_order_and_payment-order".shipping_district shipping_district,public."tbl_order_and_payment-order".shipping_police_station shipping_police_station,public."tbl_order_and_payment-order".shipping_post_code shipping_post_code,public."tbl_order_and_payment-order".pending_status pending_status,public."tbl_order_and_payment-order".pending_status_details pending_status_details,public."tbl_order_and_payment-order".pending_status_date pending_status_date,public."tbl_order_and_payment-order".cancel_status cancel_status,public."tbl_order_and_payment-order".cancel_status_details cancel_status_details,public."tbl_order_and_payment-order".cancel_status_date cancel_status_date,public."tbl_order_and_payment-order".shipped_status shipped_status,public."tbl_order_and_payment-order".shipped_status_details shipped_status_details,public."tbl_order_and_payment-order".shipped_status_date shipped_status_date,public."tbl_order_and_payment-order".confirmed_status confirmed_status,public."tbl_order_and_payment-order".confirmed_status_details confirmed_status_details,public."tbl_order_and_payment-order".confirmed_status_date confirmed_status_date,public."tbl_order_and_payment-order".processing_status processing_status,public."tbl_order_and_payment-order".processing_status_details processing_status_details,public."tbl_order_and_payment-order".processing_status_date processing_status_date,public."tbl_order_and_payment-order".cvv_id cvv_id,public."tbl_order_and_payment-order".card_name card_name,public."tbl_order_and_payment-order".card_number card_number,public."tbl_order_and_payment-order".card_month card_month,public."tbl_order_and_payment-order".card_year card_year,public."tbl_order_and_payment-order".billing_phone_number billing_phone_number,public."tbl_order_and_payment-order".purchase_date purchase_date,public."tbl_order_and_payment-order".purchase_date purchase_date,public."tbl_order_and_payment-order".card_year card_year,public."tbl_order_and_payment-order"."transaction_id" transaction_id,public."tbl_order_and_payment-order"."order_amount" order_amount,public."tbl_order_and_payment-order_items".item_id item_id, public."tbl_order_and_payment-order_items".name item_name,public."tbl_order_and_payment-order_items".price item_price,public."tbl_order_and_payment-order_items".description description FROM (public."tbl_order_and_payment-order" INNER JOIN public."tbl_order_and_payment-order_items" ON public."tbl_order_and_payment-order_items".user_payment_id= public."tbl_order_and_payment-order".id);')
get_all_checkout = data.mappings().all()
if not data:
raise HTTPException(status_code=status.HTTP_404_NOT_FOUND,detail=f"There is nothing from database")
dicts =get_all_checkout
num_0f_rows=len(dicts)
print("rows=",num_0f_rows)
row=0
while row< num_0f_rows:
question_id_student_user=dicts[row].get('order_number')
print("question_id_student_user",question_id_student_user)
break
res=question_id_student_user==list[dicts]
if dicts[row].get('order_number') == 53010:
dic=dicts[row]=num_0f_rows
return dic
from this code i can get the order number from the list of row but cannot make the list of matching items of numbers. help me