# coding=utf-8
from rest_framework import serializers
from .models import *


class DeviceSerializer(serializers.ModelSerializer):
    create_user_text = serializers.CharField(source='create_user.username', read_only=True)

    class Meta:
        model = DeviceModel
        fields = '__all__'

    def create(self, validated_data):
        validated_data['create_user'] = self.context['request'].user
        validated_data['tenant'] = self.context['request'].user.employee.tenant
        instance = super(DeviceSerializer, self).create(validated_data)
        return instance
