Ideas for implementing Datetime infinity for postgres in Django ORM

Django ORM does not support Infinity as a value for datetime fields, however postgres does. But the open ticket was closed with the reason being that there is no clear solution on how to implement this feature. It was suggested to discuss the implementation in the Djnago forums as well, so here we go. Share your ideas on implementing this feature, and how should we go about it.

I’d argue it’s not the responsibility of Django to implement postgres ↔ python type & value mapping :man_shrugging:

Please see this psycopg section on how it used to handle infinity then removed that support in favour of a user-customisable solution: Differences from psycopg2 - psycopg 3.3.0.dev1 documentation

The example shows how to setup your own definition.

Alternative to date.max / date.min is to use float('inf') / float('-inf')

2 Likes