from rest_framework import serializers
from smart.models import SmartModule, SmartPush


class SmartListSerializer(serializers.ModelSerializer):

    class Meta:
        model = SmartModule
        fields = [
            'name',
            'device_id',
            'chip_id'
        ]


class SmartPushListSerializer(serializers.ModelSerializer):
    smart = serializers.SerializerMethodField()

    class Meta:
        model = SmartPush
        fields = [
            'smart',
            'signal',
            'coordinate',
            'time',
        ]

    def get_smart(self, obj):
        return obj.smart.name
