Tasos Sangiotis

June 15, 2022

Setting a variable default datetime value in Django/python

Django comparisons almost always require timezone aware datetimes.

I tried with a None value but the comparison failed.

A workaround to keep this compatible is to use epoch and isoparse with the timezone in the ISO string.

from dateutil import parser
check_date = parser.isoparse("1970-01-01T00:00:00+03:00")


About Tasos Sangiotis

An electrical engineer at Arpedon with a broad range of interests from electrical, to mechanical & automation. Photoshooter, runner and a fan of good food & alcohol. You can also find me on Twitter, on LinkedIn, and on Instagram. If you choose to wander this wasteland do so with caution. Consider this your final warning.