2020-06-02 00:57:20 +02:00
|
|
|
from rest_framework import serializers
|
2020-06-03 18:57:53 +02:00
|
|
|
from api.models import Device
|
2020-06-02 00:57:20 +02:00
|
|
|
from telemetry.models import Telemetry
|
|
|
|
|
|
|
|
|
|
|
|
class TelemetrySerializer(serializers.ModelSerializer):
|
2020-06-03 18:57:53 +02:00
|
|
|
device = serializers.SlugRelatedField(
|
|
|
|
slug_field='serial',
|
|
|
|
queryset=Device.objects.all()
|
|
|
|
)
|
2020-06-02 00:57:20 +02:00
|
|
|
|
|
|
|
class Meta:
|
|
|
|
model = Telemetry
|
2020-06-08 23:17:16 +02:00
|
|
|
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
|