26 lines
628 B
Python
26 lines
628 B
Python
from rest_framework import serializers
|
|
from mosquito.models import MosqPost
|
|
|
|
|
|
class MosqPostListSerializer(serializers.ModelSerializer):
|
|
smart_chip = serializers.SerializerMethodField()
|
|
region = serializers.SerializerMethodField()
|
|
|
|
class Meta:
|
|
model = MosqPost
|
|
fields = [
|
|
'mosq',
|
|
'led',
|
|
'energy',
|
|
'smart_chip'
|
|
'signal',
|
|
'coordinate'
|
|
'region'
|
|
'time'
|
|
]
|
|
|
|
def get_smart_chip(self, obj):
|
|
return obj.mosq.smart_module.device_id
|
|
|
|
def get_region(self, obj):
|
|
return obj.mosq.region |