in name of god 2.0

This commit is contained in:
fjrodriguez
2023-04-12 09:20:07 -06:00
parent 42fef321e9
commit e192920a5d
5 changed files with 45 additions and 12 deletions

View File

@@ -30,7 +30,7 @@ class DeviceSerializer(serializers.ModelSerializer):
model =Device
fields = ('client','sistema','device_name','device_os', 'ip_address','token', 'macAddress', 'database',)
#this assign the masAddress value from
#this assign the masAddress value from
#the request context passed throught argument in the view to the serializer
#given that the macAddres field are read_Only in the beggining of this serialazer
#we need passing the post data to the creation instance before commited to the DB
@@ -44,13 +44,13 @@ class DeviceSerializer(serializers.ModelSerializer):
& Q(macAddress__icontains=mac_address)
& Q(database=self.context['request'].data.get('database'))
)
print('existing_devices', existing_devices)
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
suffix = existing_devices.count() + 1
mac_address += f'_{suffix}'
print('suffix mac_address',mac_address)
print('')
validated_data['macAddress']= mac_address
return super().create(validated_data)