Fix null to 0 in aggregate
This commit is contained in:
@@ -41,7 +41,6 @@ class TorrentEventConsumer(AsyncJsonWebsocketConsumer):
|
|||||||
await self.channel_layer.group_discard("torrent", self.channel_name)
|
await self.channel_layer.group_discard("torrent", self.channel_name)
|
||||||
|
|
||||||
async def dispatch(self, message):
|
async def dispatch(self, message):
|
||||||
print("dispatch ws :", message)
|
|
||||||
return await super().dispatch(message)
|
return await super().dispatch(message)
|
||||||
|
|
||||||
async def receive_json(self, content, **kwargs):
|
async def receive_json(self, content, **kwargs):
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ from django.views.generic import CreateView
|
|||||||
from django.contrib.auth import login
|
from django.contrib.auth import login
|
||||||
from django.urls import reverse_lazy
|
from django.urls import reverse_lazy
|
||||||
from django.db.models import Count, Sum, F, IntegerField
|
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.viewsets import ModelViewSet, GenericViewSet
|
||||||
from rest_framework import mixins
|
from rest_framework import mixins
|
||||||
@@ -96,9 +97,9 @@ class UserViewSet(mixins.RetrieveModelMixin,
|
|||||||
@action(methods=["get"], detail=False)
|
@action(methods=["get"], detail=False)
|
||||||
def user_stats(self, request):
|
def user_stats(self, request):
|
||||||
stats = User.objects.filter(id=request.user.id).aggregate(
|
stats = User.objects.filter(id=request.user.id).aggregate(
|
||||||
total_size=Sum("torrents__size"),
|
total_size=Coalesce(Sum("torrents__size"), 0),
|
||||||
total_torrent=Count("torrents"),
|
total_torrent=Coalesce(Count("torrents"), 0),
|
||||||
total_shared_torrent=Count("torrents_shares", distinct=True),
|
total_shared_torrent=Coalesce(Count("torrents_shares", distinct=True), 0),
|
||||||
)
|
)
|
||||||
|
|
||||||
disk_usage = shutil.disk_usage("/")
|
disk_usage = shutil.disk_usage("/")
|
||||||
|
|||||||
Reference in New Issue
Block a user