我想获取所有具有最新日期的记录。
class Report(models.Model):
id = models.AutoField(primary_key=True)
part = models.ForeignKey(Part,related_name="reports")
this_week_use = models.IntegerField(blank=True,null=True,default=0)
this_week_fail = models.IntegerField(blank=True,null=True,default=0)
this_week_fail_percent = models.DecimalField(max_digits=5,decimal_places=2,blank=True,null=True,default=0.00)
prev4_week_use = models.IntegerField(blank=True,null=True,default=0)
prev4_week_fail = models.IntegerField(blank=True,null=True,default=0)
prev4_week_fail_percent = models.DecimalField(max_digits=5,decimal_places=2,blank=True,null=True,default=0.00)
platform = models.ForeignKey(Platform,related_name="reports")
date = models.DateField(auto_now_add=True)
class Meta:
unique_together = ('part','platform','date')
我试过了
rows = Report.objects.annotate(max_date=Max('date').filter(date=max_date))
导致没有数据