mirror of
https://github.com/daniviga/bite.git
synced 2024-12-24 17:21:25 +01:00
22 lines
640 B
Python
22 lines
640 B
Python
from rest_framework import serializers
|
|
from api.models import Device, device_validation
|
|
|
|
|
|
class DeviceSerializer(serializers.ModelSerializer):
|
|
serial = serializers.CharField(
|
|
max_length=128,
|
|
validators=[device_validation],
|
|
) # disable unique validation
|
|
|
|
class Meta:
|
|
model = Device
|
|
fields = '__all__'
|
|
read_only_fields = ('creation_time', 'updated_time')
|
|
|
|
def create(self, validated_data):
|
|
device, created = Device.objects.update_or_create(
|
|
serial=validated_data['serial'],
|
|
defaults={'serial': validated_data['serial']},
|
|
)
|
|
return device
|