我试图在django视图中加入2个表。我目前有两个型号
可以在自动收报机和日期上完成加入。因为两种型号都有它们。
SSALiReport.objects.all()
NELiReport.objects.all()
NELI 看起来像这样
{
"clout": 40000,
"date": "2018-05-15",
"sentiment": 500,
"ticker": "AAPL"
},
SALI 看起来像这样
{
"date": "2018-05-15",
"market": "NYSE",
"prediction": 0.6,
"price": 300,
"ticker": "AAPL"
},
我想要第三个看起来像这样的视图,我们称之为 FullReport
{
"date": "2018-05-15",
"market": "NYSE",
"prediction": 0.6,
"price": 300,
"ticker": "AAPL",
"clout": 40000,
"sentiment": 500
},
如何在视图中提取此内容?另请注意,我希望能够按日期排列很多行。所以我需要加入两个表
供参考,参见模型
from django.contrib.postgres.fields import JSONField
from django.db import models
import datetime
# Create your models here.
class SSALiReport(models.Model):
date = models.DateField()
ticker = models.CharField(max_length=10,default='NA')
market = models.CharField(max_length=250,default='NA')
price = models.FloatField()
prediction = models.FloatField()
def __str__(self):
return str(self.date) + " - " + str(self.ticker)
class NELiReport(models.Model):
date = models.DateField()
ticker = models.CharField(max_length=10,default='NA')
sentiment = models.FloatField(default='0.0')
clout = models.FloatField(default='0.0')
top_news = JSONField(default='{}')
def __str__(self):
return str(self.date) + " - " + str(self.ticker)
此SQL脚本正常工作
SELECT *
FROM api_neli_report, api_ssali_report
WHERE api_neli_report.ticker = api_ssali_report.ticker
AND api_neli_report.date = api_ssali_report.date
什么是django等价物?