1
0
mirror of https://github.com/daniviga/bite.git synced 2024-11-23 05:16:13 +01:00
bite/freedcs/api/serializers.py
Daniele Viganò 4cebe6a8f5
Manage serial numbers on POST (#7)
* Update subscription if exists

* POST with serial #
2020-06-03 18:57:53 +02:00

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