# coding=utf-8

from rest_framework import serializers
from .models import Notices


class NoticesSerializer(serializers.ModelSerializer):
    create_user_name = serializers.CharField(source='create_user.employee.name', read_only=True)
    type_text = serializers.CharField(source='get_type_display', read_only=True)
    range_text = serializers.CharField(source='get_range_display', read_only=True)
    class Meta:
        model = Notices
        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(NoticesSerializer, self).create(validated_data)
        return instance


class NoticesWXSerializer(serializers.ModelSerializer):
    class Meta:
        model = Notices
        fields = '__all__'
