0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

Django Sumの集計結果がNoneだった場合に0にする

Posted at

DjangoでSumの集計結果がNoneだった場合に0にするやり方

以下のコードを書いてたときにpointがNoneになるとその後の計算が出来なくなる

point = ThanksCard.objects.filter(f_delete=False, thankseval_id=thankseval_id,from_staff_id=select_user_id).aggregate(Sum('point'))

なのでCoalesceを使えとのこと

point = ThanksCard.objects.filter(f_delete=False, thankseval_id=thankseval_id,from_staff_id=select_user_id).aggregate(Coalesce(Sum('point'),0))

無事0になりました。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?