@user_passes_test(lambda u: u.is_staff, login_url='/pyramid/login/')
def defaulters_report(request):
template = 'private/admin/report_defaulters.html'
queryset = list(TreeNode.objects.all())
for x in queryset:
x.d = x.debt
defaulters = TreeNode.objects.filter(id__in=([x.id for x in queryset if x.d > 0]))
context = dict()
unpaid_purepro = defaulters[0].annuities.all()
for x in list(defaulters)[1:]:
unpaid_purepro = unpaid_purepro | x.annuities.all()
unpaid_purepro = unpaid_purepro.filter(expected_date__lt=timezone.now())
context['total'] = unpaid_purepro.all().aggregate(Sum('total'))['total__sum']
return render(request, template, context)
ながら<クラスのdjango.db.models.QuerySet '>のためのreprを取得できません - 私は質問のタイトルのようなエラーが出ます。最終的なエラーの表示は:私はunpaid_pureproの値を取得しようとすると集計データが
Expression tree is too large (maximum depth 1000)
私は間違っていますか?あなたの
class TreeNode(MPTTModel):
class Meta:
verbose_name = 'участник'
verbose_name_plural = 'участники'
# account for auth
account = models.OneToOneField(User, verbose_name='аккаунт', related_name='treenode')
@property
def debt(self):
...
@property
def last_payment(self):
return self.annuities.last()
@property
def pay_progress(self):
return "{}/{}".format(self.annuities.exclude(fact_date=None).aggregate(Sum('total'))['total__sum'],
self.annuities.aggregate(Sum('total'))['total__sum'])
class FilterPayment(models.Model):
class Meta:
verbose_name = 'взнос за фильтр'
verbose_name_plural = 'взносы за фильтр'
expected_date = models.DateField(verbose_name='ожидаемая дата')
fact_date = models.DateField(verbose_name='фактическая дата', null=True, blank=True)
total = models.IntegerField(verbose_name='сумма')
client = models.ForeignKey(TreeNode, related_name='annuities', verbose_name='клиент')
CASH = 1
TERMINAL = 2
METHOD_CHOICES = (
(CASH, "Cash"),
(TERMINAL, "Mobilnik")
)
method = models.PositiveSmallIntegerField(choices=METHOD_CHOICES, default=1)
あなたが質問を更新することができますし、あなたのモデルのコードを追加しますか? –
'debt'プロパティのコードを追加できますか? –