add database to Device model

This commit is contained in:
fjrodriguez
2023-04-10 08:10:02 -06:00
parent d928f0eeb2
commit f24b33b0a2
5 changed files with 35 additions and 13 deletions

View File

@@ -28,7 +28,7 @@ class DeviceSerializer(serializers.ModelSerializer):
macAddress = serializers.CharField(read_only=True)
class Meta:
model =Device
fields = ('client','sistema','device_name','device_os', 'ip_address','token', 'macAddress')
fields = ('client','sistema','device_name','device_os', 'ip_address','token', 'macAddress', 'database',)
#this assign the masAddress value from
#the request context passed throught argument in the view to the serializer
@@ -39,8 +39,12 @@ class DeviceSerializer(serializers.ModelSerializer):
sistema = validated_data['sistema']
client = validated_data['client']
existing_devices = Device.objects.filter(
Q(sistema=sistema)& Q(client=client)& Q(macAddress__icontains=mac_address)
Q(sistema=sistema)
& Q(client=client)
& Q(macAddress__icontains=mac_address)
& Q(database=self.context['request'].data.get('database'))
)
if existing_devices.exists():
# A device with the same macAddress already exists for the given sistema and client
# Get the number of existing devices and add 1 to create a new suffix