Development of an internal social media platform with personalised dashboards for students
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

functions.py 768B

12345678910111213141516171819202122
  1. from django.db.models import DecimalField, DurationField, Func
  2. class IntervalToSeconds(Func):
  3. function = ''
  4. template = """
  5. EXTRACT(day from %(expressions)s) * 86400 +
  6. EXTRACT(hour from %(expressions)s) * 3600 +
  7. EXTRACT(minute from %(expressions)s) * 60 +
  8. EXTRACT(second from %(expressions)s)
  9. """
  10. def __init__(self, expression, *, output_field=None, **extra):
  11. super().__init__(expression, output_field=output_field or DecimalField(), **extra)
  12. class SecondsToInterval(Func):
  13. function = 'NUMTODSINTERVAL'
  14. template = "%(function)s(%(expressions)s, 'SECOND')"
  15. def __init__(self, expression, *, output_field=None, **extra):
  16. super().__init__(expression, output_field=output_field or DurationField(), **extra)