[Answered ]-Django – Geting fields by values_list in queryset

1👍

You can evaluate a QuerySet and convert the result to a list with:

list(stocks_query.values_list('Date', flat=True))

This will thus produce a list of date objects.

You can convert these for example to YYYY-MM-DD-formatted strings with:

list(map(str, stocks_query.values_list('Date', flat=True)))

or to datetime objects with:

from datetime import datetime

[datetime.fromordinal(d.toordinal()) for d in stocks_query.values_list('Date', flat=True)]

Leave a comment