queries.py 752 B

1234567891011121314151617181920212223242526272829303132
  1. from django.db import connection
  2. class Query:
  3. #@staticmethod
  4. def sql_query(method):
  5. def wrapper():
  6. with connection.cursor() as cursor:
  7. method(cursor)
  8. return wrapper
  9. @sql_query
  10. #@staticmethod
  11. def get_tickets(cursor):
  12. cursor.execute("""
  13. SELECT
  14. tickets_task.id,
  15. tickets_task.title,
  16. SharixAdmin_sharixuser.username,
  17. tickets_task.created_by_id,
  18. tickets_task.priority
  19. FROM
  20. tickets_task
  21. JOIN
  22. SharixAdmin_sharixuser
  23. ON
  24. tickets_task.created_by_id == SharixAdmin_sharixuser.id
  25. ORDER BY
  26. tickets_task.priority;
  27. """)
  28. rows = cursor.fetchall()
  29. print(rows)