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