我希望在我的查询中包含其他表中的列。我希望在我的输出中包含报告中的所有列以及产品和制造商中的名称列。
我当前的查询如下所示:
latest = Report.objects.values('date').latest('date')['date'].strftime('%Y-%m-%d')`]
rows = Report.objects.filter(date=latest).order_by('platform')
--
#
class Manufacturer(models.Model):
id = models.AutoField(primary_key=True)
name = models.CharField(blank=False,null=False,unique=True,max_length=100)
comment = models.CharField(blank=True,null=True,max_length=200)
def __unicode__(self):
return u'%s' % self.name
#
class Product(models.Model):
id = models.AutoField(primary_key=True)
name = models.CharField(blank=False,null=False,unique=True,max_length=100)
manufacturer = models.ForeignKey(Manufacturer,related_name="products",null=True,blank=True)
comment = models.CharField(blank=True,null=True,max_length=200)
timestamp = models.DateTimeField(auto_now_add=True)
def __unicode__(self):
return u'%s' % self.name
#
class Part(models.Model):
id = models.AutoField(primary_key=True)
name = models.CharField(blank=False,null=False,unique=True,max_length=100)
product = models.ForeignKey(Product,related_name="parts",null=True,blank=True)
comment = models.CharField(blank=True,null=True,max_length=200)
timestamp = models.DateTimeField(auto_now_add=True)
def __unicode__(self):
return u'%s' % self.name
#
class Platform(models.Model):
id = models.AutoField(primary_key=True)
name = models.CharField(blank=False,null=False,unique=True,max_length=100)
comment = models.CharField(blank=True,null=True,max_length=200)
timestamp = models.DateTimeField(auto_now_add=True)
def __unicode__(self):
return u'%s' % self.name
#
class Report(models.Model):
id = models.AutoField(primary_key=True)
part = models.ForeignKey(Part,related_name="reports")