0

How can I find out the type by accessing the column of the index of the models.all() result??

My code is like this:

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

but this at index : index : {'board_seq': Decimal('15'), 'board_title': '제목', 'board_content': '내용', 'board_writer': '무명', 'board_password': '1234', 'create_date': datetime.datetime(2021, 11, 27, 18, 6, 8, 586137)}

and in the column : column : board_seq type:<class 'str'>

What I want to do is find the datetime.datetime, not the str.

이정훈
  • 11
  • 2
  • 1
    Does this answer your question? [Iterating over dictionaries using 'for' loops](https://stackoverflow.com/questions/3294889/iterating-over-dictionaries-using-for-loops) – Abdul Aziz Barkat Nov 27 '21 at 09:40

1 Answers1

0

You can look at the type of the corresponding value with:

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)}')
Willem Van Onsem
  • 443,496
  • 30
  • 428
  • 555
  • index[column] = value.strftime("%Y-%d-%m %H:%M:%S") and finally return result_model I solved this thank you – 이정훈 Nov 27 '21 at 09:56