feat: count_state统计数据增加
This commit is contained in:
parent
b71a8921c3
commit
826cb8c8b1
|
@ -1,5 +1,5 @@
|
|||
from django.contrib import admin
|
||||
from apps.em.models import Ecate
|
||||
from apps.em.models import Ecate, Equipment
|
||||
# Register your models here.
|
||||
|
||||
|
||||
|
@ -7,3 +7,9 @@ from apps.em.models import Ecate
|
|||
class EcateAdmin(admin.ModelAdmin):
|
||||
list_display = ('id', 'name', 'code', 'type',
|
||||
'is_for_safe', 'is_for_enp', 'is_car')
|
||||
|
||||
|
||||
@admin.register(Equipment)
|
||||
class EquipmentAdmin(admin.ModelAdmin):
|
||||
list_display = ('id', 'name', 'type',
|
||||
'cate', 'state', 'is_online', 'running_state')
|
||||
|
|
|
@ -32,6 +32,9 @@ class Ecate(CommonADModel):
|
|||
is_for_enp = models.BooleanField('是否用于环保', default=False)
|
||||
is_car = models.BooleanField('是否为车辆', default=False)
|
||||
|
||||
def __str__(self):
|
||||
return f'{self.name}|{self.code}'
|
||||
|
||||
|
||||
class Equipment(CommonBModel):
|
||||
"""
|
||||
|
|
|
@ -70,6 +70,7 @@ class EquipmentViewSet(CustomModelViewSet):
|
|||
"""
|
||||
queryset = self.filter_queryset(self.get_queryset())
|
||||
result = queryset.aggregate(
|
||||
count=Count('id'),
|
||||
count_online=Count(
|
||||
Case(When(is_online=1, then=1), output_field=IntegerField())),
|
||||
count_offline=Count(
|
||||
|
@ -86,6 +87,7 @@ class EquipmentViewSet(CustomModelViewSet):
|
|||
Case(When(running_state=50, then=1), output_field=IntegerField()))
|
||||
)
|
||||
json_result = {
|
||||
'count': result['count'],
|
||||
'count_online': result['count_online'],
|
||||
'count_offline': result['count_offline'],
|
||||
'count_running': result['count_running'],
|
||||
|
|
Loading…
Reference in New Issue