1
0
mirror of https://github.com/daniviga/bite.git synced 2024-12-24 17:21:25 +01:00
bite/beer/api/serializers.py
Daniele Viganò 09cf23554a
Project renaming (#14)
* Renaming

* Make Django migrations sync to DB availability
2020-06-17 20:08:10 +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