Is there a way to make date fields timezone unaware when querying a Django model to save in Excel file?
I'm querying my model like this:
info = Prorrogation.objects.using('test_database').exclude(
contractDate__gte=date.today()
).filter(
contractDate__gte=data
).order_by('companyName').values()
Then I build a DataFrame using pandas and save a report in excel format, but I'm getting the error Excel does not support datetimes with timezones. Please ensure that datetimes are timezone unaware before writing to Excel.
, is there a way for me to make the date fields timezone unaware when I query the model?
You can make the date time to timezone-naive format (i.e., a plain datetime object) before querying the model
from django.utils import timezone
info = Prorrogation.objects.using('test_database').exclude(
contractDate__gte=timezone.make_naive(date.today())
).filter(
contractDate__gte=timezone.make_naive(data)
).order_by('companyName').values()