Fix null to 0 in aggregate
This commit is contained in:
@@ -3,6 +3,7 @@ from django.views.generic import CreateView
|
||||
from django.contrib.auth import login
|
||||
from django.urls import reverse_lazy
|
||||
from django.db.models import Count, Sum, F, IntegerField
|
||||
from django.db.models.functions import Coalesce
|
||||
|
||||
from rest_framework.viewsets import ModelViewSet, GenericViewSet
|
||||
from rest_framework import mixins
|
||||
@@ -96,9 +97,9 @@ class UserViewSet(mixins.RetrieveModelMixin,
|
||||
@action(methods=["get"], detail=False)
|
||||
def user_stats(self, request):
|
||||
stats = User.objects.filter(id=request.user.id).aggregate(
|
||||
total_size=Sum("torrents__size"),
|
||||
total_torrent=Count("torrents"),
|
||||
total_shared_torrent=Count("torrents_shares", distinct=True),
|
||||
total_size=Coalesce(Sum("torrents__size"), 0),
|
||||
total_torrent=Coalesce(Count("torrents"), 0),
|
||||
total_shared_torrent=Coalesce(Count("torrents_shares", distinct=True), 0),
|
||||
)
|
||||
|
||||
disk_usage = shutil.disk_usage("/")
|
||||
|
||||
Reference in New Issue
Block a user