嗨,我正在试着制作一张桌子,这张桌子将有一天的出租车行程。1次出租车旅行的特点之一是包括一张在该次旅行中使用的所有折扣清单。
可以使用任意数量的折扣。我不知道该如何做,如何将折扣列表包含在一个项目属性中?因此,基本上,将一个包含属性列表的项写入DynamoDB?
这是我的桌子:
def create_table(self):
table = dynamodb.create_table(
TableName='TaxiTable',
KeySchema=[
{
'AttributeName': 'trip',
'KeyType': 'HASH'
},
],
AttributeDefinitions=[
{
'AttributeName': 'trip',
'AttributeType': 'S'
},
],
ProvisionedThroughput={
'ReadCapacityUnits': 10,
'WriteCapacityUnits': 10
}
)
print("Table status:", table.table_status)“旅行”的关键是一根长串,上面写着那辆出租车的起源,当天最后一站是在那里,出租车号码,停车次数,以及行程的日期。
trip_key: 12thAve.MapleDrive.0124.02.02202020下面作为一个属性,我想要一张清单,列出在那次出租车旅行中使用的所有折扣/类似于:
trip_key: 12thAve.MapleDrive.0124.02.02202020
discount_map:
{
discount1: { name: 'Senior', total_saved: '10'},
discount2: { name: 'Student', total_saved: '30'},
discount3: { name: 'Employee', total_saved: '20'},
discount4: { name: 'Hotel', total_saved: '30'}
}我不知道一次旅行可以打多少折。可能在5-10之间。但我想把所有的折扣包括在一个插入。我想查询在出租车旅行中使用的特定折扣,以及从这个表中节省的总额。
我不知道首先是否应该将列表转换为JSON对象?或者,如果有一种方法可以遍历列表并按我的意愿插入它。
import boto3
class taxi_discount:
name = None
total_saved = None
# rest of logic for this class...
class insert_to_dynamoDb:
dynamodb = boto3.resource('dynamodb', region_name='us-west-2', endpoint_url="http://localhost:8000")
taxi_trip_key= None
taxi_discounts_list = []
def __init__(taxi_trip, discount_list):
self.taxi_trip_key= taxi_trip
self.discount_list = discount_list
def write_to_table(self):
table = dynamodb.Table('TaxiTable')
response = table.put_item(
Item={
'trip': taxi_trip_key,
'discount_map': taxi_discounts_list
}
} )https://stackoverflow.com/questions/60267884
复制相似问题