Django压缩多个具有不常见字段d的查询集

2024-04-19 19:11:36 发布

您现在位置:Python中文网/ 问答频道 /正文

我有一个模型,在这个模型中,我每月都会获取published countunder process countrejected countreceived count

class PreData(models.Model):

    status=models.CharField(max_length=200,default=None,null=True)

    receivedon=models.DateField(default=None,blank=False,null=True)

    publishedon = models.DateField(default=None, blank=True, null=True)

在cd7}模型中,

在编写完下面的查询之后,我很难理解如何获取数据来填充列(见图)。我不确定我写的查询是否有用。在

当我想压缩received_monthly_datapublished_monthly_data时,问题就来了,但是received_monthly_data有四月月份的数据,而{}没有四月月份。当我压缩的时候,4月的结果就会下降。我不知道该怎么做。在

^{pr2}$

I need the data to fill these columns

我们非常感谢您的帮助。在


Tags: 模型nonetruedefaultdatamodelscountnull
1条回答
网友
1楼 · 发布于 2024-04-19 19:11:36

也许您可以使用itertools.zip_longest,它将压缩最长的序列,并用None替换较短序列中丢失的值。这样你就不会丢失4月份的数据。在

如果要使用None以外的值,请指定fillvalue参数。在

来自https://docs.python.org/3/library/itertools.html#itertools.zip_longest

itertools.zip_longest(*iterables, fillvalue=None)

Make an iterator that aggregates elements from each of the iterables. If the iterables are of uneven length, missing values are filled-in with fillvalue. Iteration continues until the longest iterable is exhausted.

注意,在Python2中,这个函数被称为itertools.izip_longest。在

相关问题 更多 >