【问题标题】:How can I find out the type by accessing the column of the index of the models.all() result?如何通过访问 models.all() 结果的索引列来找出类型?
【发布时间】:2022-01-05 01:23:34
【问题描述】:

如何通过访问models.all()结果的索引列找出类型??

我的代码是这样的:

def qtj(result_model):
    for index in result_model:
        print('index : ', index)
        for column in index:
            print(f'column : {column} type:{type(column)}')

但这在索引处: 索引:{'board_seq':十进制('15'),'board_title':'제목','board_content':'내용','board_writer':'무명','board_password':'1234','create_date': datetime.datetime(2021, 11, 27, 18, 6, 8, 586137)}

并在列中: 列:board_seq 类型:

我想做的是找到 datetime.datetime,而不是 str。

【问题讨论】:

标签: python python-3.x django django-models django-orm


【解决方案1】:

可以通过以下方式查看对应值的类型:

def qtj(result_model):
    for index in result_model:
        print('index : ', index)
        for column, value in index.items():
            print(f'column : {column} type:{type(value)}')

【讨论】:

  • index[column] = value.strftime("%Y-%d-%m %H:%M:%S") 最后返回 result_model 我解决了这个谢谢
猜你喜欢
  • 1970-01-01
  • 2022-11-20
  • 1970-01-01
  • 1970-01-01
  • 2019-07-23
  • 1970-01-01
  • 2020-06-30
  • 2016-01-15
  • 1970-01-01
相关资源
最近更新 更多