Django - set DateTimeField default to timezone.datetime.max

datetime, django

Solution

`timezone.datetime` - this is regular python `datetime.datetime` module which is imported in `django.utils.timezone` and it returns regular datetime, so you need to make it aware:

timezone.make_aware(timezone.datetime.max, timezone.get_default_timezone())

Problem

I'm trying to set the default value for a datetime field to the max date `timezone.datetime.max` ``` from django.db import models from django.utils import timezone class Item(models.Model): id = models.AutoField(primary_key=True) deleted = models.DateTimeField(default=timezone.datetime.max) ``` And i'm getting this error when ever i try to save a new object to the db ``` /usr/local/lib/python2.7/dist-packages/django/db/models/fields/__init__.py:903: RuntimeWarning: DateTimeField Item.deleted received a naive datetime (9999-12-31 23:59:59.999999) while time zone support is active. RuntimeWarning) ``` So reading the docs on this issue i'v set `USE_TZ=True` and i've got `pytz` installed.

Original source