Pynamodb动态JSON序列化

2024-09-28 21:39:33 发布

您现在位置:Python中文网/ 问答频道 /正文

我有一个复合模型看起来像这:在

class Parser(MapAttribute):
    ParserType = UnicodeAttribute()
    MailBody = UnicodeAttribute()
    BestTemplate = UnicodeAttribute(null=True)
    ParseStatus = ParseStatus()
    ParsedOutput = JSONAttribute()


class OMPStatusModel(Model):
    """
    PynamoDB Model handling table OMPStatus
    """


    class Meta:
        table_name = 'OMPStatus'
        region = 'us-east-1'
    SNSMessageID = UnicodeAttribute(hash_key=True)
    CreatedDateTime = UTCDateTimeAttribute()
    UpdatedDateTime = UTCDateTimeAttribute(null=True)
    CompletedDateTime = UTCDateTimeAttribute(null=True)
    ProcessStatus = UnicodeAttribute()
    ErrorDetail = UnicodeAttribute(default="Not set")
    SES = SES(null=True)
    SNS = SNS(null=True)
    Parser = Parser(null=True)

除了ParsedOutput存储为DynamoDB中的键值对列表外,这一切都很好。为了便于支持团队阅读,我想把它分解成自己的属性列表—为了便于讨论,假设它们都可以是UnicodeAttribute()。在

我在想我应该能做点什么比如:在

^{pr2}$

那就做点什么吧比如:在

OMPStatusModel.update(actions=[OMPStatusModel.SES.set(kwargs[key]),
                          OMPStatusModel.UpdatedDateTime.set(datetime.now())])

不太明白,因为它不太管用。 有什么建议吗?在


Tags: keytrueparsermodeltablenullclassses