add database to Device model
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user