1
0
mirror of https://github.com/daniviga/bite.git synced 2024-11-30 08:36:14 +01:00
bite/freedcs/api/serializers.py

22 lines
640 B
Python
Raw Normal View History

2020-06-02 00:57:20 +02:00
from rest_framework import serializers
from api.models import Device, device_validation
2020-06-02 00:57:20 +02:00
class DeviceSerializer(serializers.ModelSerializer):
serial = serializers.CharField(
max_length=128,
validators=[device_validation],
) # disable unique validation
2020-06-02 00:57:20 +02:00
class Meta:
model = Device
fields = '__all__'
read_only_fields = ('creation_time', 'updated_time')
2020-06-02 00:57:20 +02:00
def create(self, validated_data):
device, created = Device.objects.update_or_create(
serial=validated_data['serial'],
defaults={'serial': validated_data['serial']},
)
return device