gpt4 book ai didi

linux - 我想按月分组怎么办?在django中

转载 作者:太空宇宙 更新时间:2023-11-04 05:22:25 25 4
gpt4 key购买 nike

sumary = Profile.objects.values('user_report__created_date__month')

错误无法将关键字“月份”解析为字段。不允许在“created_date”加入。

    class Profile(models.Model):
first_name = models.CharField(max_length=100, verbose_name=_('Имя'))
last_name = models.CharField(max_length=100)



class Department(models.Model):
number = models.IntegerField(default=0)
name = models.CharField(max_length=150, default=None)

def __unicode__(self):
return self.name


class Report(models.Model):
user = models.ForeignKey(Profile, related_name='user_report')
department = models.ForeignKey(Department, related_name='report')
created_date = models.DateTimeField()
edited_by = models.ForeignKey(User)
edited_at = models.DateTimeField(default=timezone.now())

def __unicode__(self):
return self.department.name

class Meta:
verbose_name = _('Отчет')
verbose_name_plural = _('Отчеты')


class Statistic(models.Model):
name = models.CharField(max_length=90)
value = models.IntegerField()
report = models.ForeignKey(Report, related_name='stat_report')

def __unicode__(self):
return self.name

最佳答案

你可能想要这样的东西:

end_date = datetime.datetime.now() - datetime.timedelta(days=31)
start_date = datetime.datetime.now()
summary = Profile.objects.filter(user_report__range=(start_date, end_date))

这是为了获取一个月的用户报告。那是对的吗?如果您想要更准确的答案,请添加更多代码。

关于linux - 我想按月分组怎么办?在django中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39676593/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com