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

* Make Django migrations sync to DB availability
2020-06-17 20:08:10 +02:00

21 lines
608 B
Python

from rest_framework import serializers
from api.models import Device
from telemetry.models import Telemetry
class TelemetrySerializer(serializers.ModelSerializer):
device = serializers.SlugRelatedField(
slug_field='serial',
queryset=Device.objects.all()
)
class Meta:
model = Telemetry
fields = ('time', 'device', 'clock', 'transport', 'payload',)
read_only_fields = ['transport']
def create(self, validated_data):
validated_data['transport'] = 'http'
telemetry = Telemetry.objects.create(**validated_data)
return telemetry