from django.db.backends.signals import connection_created
from django.dispatch import receiver

@receiver(connection_created)
def extend_sqlite(connection=None, **kwargs):
    connection.connection.create_function('least', 2, min)
connection.connection.create_function('greatest', 2, max)
Как расширить SQLite функциями Python в Django?