from django.dispatch import receiver

@receiver(connection_created)
def extend_sqlite(connection=None, **kwargs):
    connection.connection.create_function('least', 2, min)
How to extend SQLite with Python functions in Django?