|
@@ -193,6 +193,8 @@ class GatewayFamilyRoomView(View):
|
|
sub_device_qs = GatewaySubDevice.objects.filter(id=item['sub_device']).values('id',
|
|
sub_device_qs = GatewaySubDevice.objects.filter(id=item['sub_device']).values('id',
|
|
'device_type',
|
|
'device_type',
|
|
'nickname')
|
|
'nickname')
|
|
|
|
+ if not sub_device_qs.exists():
|
|
|
|
+ continue
|
|
device_dict = {
|
|
device_dict = {
|
|
'deviceId': sub_device_qs[0]['id'],
|
|
'deviceId': sub_device_qs[0]['id'],
|
|
'deviceType': sub_device_qs[0]['device_type'],
|
|
'deviceType': sub_device_qs[0]['device_type'],
|
|
@@ -204,21 +206,34 @@ class GatewayFamilyRoomView(View):
|
|
|
|
|
|
device_not_room = []
|
|
device_not_room = []
|
|
device_not_room_qs = FamilyRoomDevice.objects.filter(family_id=family_id)
|
|
device_not_room_qs = FamilyRoomDevice.objects.filter(family_id=family_id)
|
|
- device_not_room_qs = device_not_room_qs.filter(~Q(room_id=room_id)).values('device_id').annotate(
|
|
|
|
- count=Count('device_id')).values('room_id', 'device_id', 'device__Type', 'device__NickName')
|
|
|
|
|
|
+ device_not_room_qs = device_not_room_qs.filter(~Q(room_id=room_id)).values('room_id', 'device_id',
|
|
|
|
+ 'device__Type', 'device__NickName',
|
|
|
|
+ 'sub_device')
|
|
if device_not_room_qs.exists():
|
|
if device_not_room_qs.exists():
|
|
for item in device_not_room_qs:
|
|
for item in device_not_room_qs:
|
|
name = ''
|
|
name = ''
|
|
- if room_device_qs.exists():
|
|
|
|
- family_room_qs = FamilyRoom.objects.filter(id=item['room_id'])
|
|
|
|
- if family_room_qs.exists():
|
|
|
|
- name = family_room_qs.first().name
|
|
|
|
- device_not_room.append({
|
|
|
|
- 'deviceId': item['device_id'],
|
|
|
|
- 'deviceType': item['device__Type'],
|
|
|
|
- 'nickName': item['device__NickName'],
|
|
|
|
- 'roomName': name
|
|
|
|
- })
|
|
|
|
|
|
+ family_room_qs = FamilyRoom.objects.filter(id=item['room_id'])
|
|
|
|
+ if family_room_qs.exists():
|
|
|
|
+ name = family_room_qs.first().name
|
|
|
|
+ if not item['sub_device']:
|
|
|
|
+ device_not_room.append({
|
|
|
|
+ 'deviceId': item['device_id'],
|
|
|
|
+ 'deviceType': item['device__Type'],
|
|
|
|
+ 'nickName': item['device__NickName'],
|
|
|
|
+ 'roomName': name
|
|
|
|
+ })
|
|
|
|
+ else:
|
|
|
|
+ sub_device_qs = GatewaySubDevice.objects.filter(id=item['sub_device']).values('id',
|
|
|
|
+ 'device_type',
|
|
|
|
+ 'nickname')
|
|
|
|
+ if not sub_device_qs.exists():
|
|
|
|
+ continue
|
|
|
|
+ device_not_room.append({
|
|
|
|
+ 'deviceId': sub_device_qs[0]['id'],
|
|
|
|
+ 'deviceType': sub_device_qs[0]['device_type'],
|
|
|
|
+ 'nickName': sub_device_qs[0]['nickname'],
|
|
|
|
+ 'roomName': name
|
|
|
|
+ })
|
|
return response.json(0, {'deviceRooms': device_room, 'deviceNotRooms': device_not_room})
|
|
return response.json(0, {'deviceRooms': device_room, 'deviceNotRooms': device_not_room})
|
|
|
|
|
|
@staticmethod
|
|
@staticmethod
|