Я пытаюсь выяснить, как я могу преобразовать следующий запрос в запрос Djangon ORM.Я использую Django 2.1 Python 3.5 для Windows, я пытаюсь выполнить запрос к базе данных Oracle
SELECT m.msg_no, q.seq, To_Char(m.date_created,'yyyy/mm/dd hh24:mi:ss'), To_Char(SYSDATE,'yyyy/mm/dd hh24:mi:ss'), q.name, Round((round(SYSDATE - m.date_created,6)*1440),1) AS msg_age
FROM message m
INNER JOIN queue q ON m.queue = q.seq
WHERE m.date_created >= (SYSDATE - 13/24)
AND m.status1 = 0
AND m.direction = 0;
У меня есть две модели, я хотел бы знать, как лучше, таблицы Message и Queue связаныпо первичному ключу очереди SEQ и внешнему ключу сообщения QUEUE, поэтому SEQ == QUEUE в таблице сообщений:
from django.db import models
# Create your models here.
class Queue(models.Model):
SEQ = models.IntegerField(primary_key=True,)
NAME = models.CharField(max_length = 50)
INPUT_DRIVER = models.IntegerField()
OUTPUT_DRIVER = models.IntegerField()
DIRECTION = models.IntegerField()
ORIGINATOR = models.IntegerField()
DESTINATOR = models.IntegerField()
PRIORITY = models.IntegerField()
INPUTEXEC = models.CharField(max_length = 100)
OUTPUTEXEC = models.CharField(max_length = 100)
USERID = models.CharField(max_length = 8)
TMSTAMP = models.DateTimeField(max_length = 7)
QUEUE_TYPE = models.CharField(max_length = 16)
class Meta:
db_table = "QUEUE"
#
class Message(models.Model):
MSG_NO = models.IntegerField(primary_key=True,)
MSG_TYPE = models.IntegerField()
DIRECTION = models.IntegerField()
SESSION_NO = models.IntegerField()
SEQUENCE_NO = models.IntegerField()
REF_SESSION = models.IntegerField()
REF_SEQUENCE = models.IntegerField()
ACKTIME = models.DateTimeField(max_length = 7)
ACKNAKSTATUS = models.IntegerField()
PRIORITY = models.CharField(max_length = 1)
DELIVMONITOR = models.IntegerField()
OBSOLESCENCE = models.IntegerField()
DISPOSITION = models.IntegerField()
TRAILER = models.IntegerField()
BYPASSED = models.IntegerField()
RESPONSE_QUEUE = models.IntegerField()
SOURCE_QUEUE = models.IntegerField()
QUEUE = models.IntegerField()
QUEUE_PRIORITY = models.IntegerField()
DATE_CREATED = models.DateTimeField(max_length = 7)
DATE_ROUTED = models.DateTimeField(max_length = 7)
INPUT_FILE = models.IntegerField()
OUTPUT_FILE = models.IntegerField()
STATUS1 = models.IntegerField()
STATUS2 = models.IntegerField()
STATUS3 = models.IntegerField()
USERID = models.CharField(max_length = 8)
TMSTAMP = models.DateTimeField(max_length = 7)
class Meta:
db_table = "MESSAGE"