29 lines
1019 B
Python
29 lines
1019 B
Python
from rest_framework import viewsets
|
|
from .models import Place
|
|
from .serializers import PlaceSerializer
|
|
from drf_yasg.utils import swagger_auto_schema
|
|
from drf_yasg import openapi
|
|
|
|
class PlaceViewSet(viewsets.ModelViewSet):
|
|
"""
|
|
地点标签管理接口
|
|
"""
|
|
queryset = Place.objects.filter(parent=None) # 只获取顶级节点
|
|
serializer_class = PlaceSerializer
|
|
|
|
@swagger_auto_schema(
|
|
operation_summary='获取地点标签树',
|
|
operation_description='返回所有地点标签的树形结构数据',
|
|
responses={200: PlaceSerializer(many=True)}
|
|
)
|
|
def list(self, request, *args, **kwargs):
|
|
return super().list(request, *args, **kwargs)
|
|
|
|
@swagger_auto_schema(
|
|
operation_summary='创建地点标签',
|
|
operation_description='创建新的地点标签',
|
|
request_body=PlaceSerializer,
|
|
responses={201: PlaceSerializer()}
|
|
)
|
|
def create(self, request, *args, **kwargs):
|
|
return super().create(request, *args, **kwargs) |