feat: 添加paper list 接口
This commit is contained in:
parent
0018597006
commit
be6a75bd45
|
|
@ -0,0 +1,7 @@
|
|||
from apps.utils.serializers import CustomModelSerializer
|
||||
from .models import Paper
|
||||
|
||||
class PaperListSerializer(CustomModelSerializer):
|
||||
class Meta:
|
||||
model = Paper
|
||||
fields = '__all__'
|
||||
|
|
@ -0,0 +1,13 @@
|
|||
from django.urls import path, include
|
||||
from rest_framework import routers
|
||||
from .views import PaperViewSet
|
||||
|
||||
API_BASE_URL = 'api/resm/'
|
||||
HTML_BASE_URL = 'resm/'
|
||||
|
||||
router = routers.DefaultRouter()
|
||||
router.register('paper', PaperViewSet, basename="paper")
|
||||
|
||||
urlpatterns = [
|
||||
path(API_BASE_URL, include(router.urls))
|
||||
]
|
||||
|
|
@ -1,3 +1,24 @@
|
|||
from django.shortcuts import render
|
||||
from rest_framework.response import Response
|
||||
from .models import Paper, PaperAbstract
|
||||
from .serializers import PaperListSerializer
|
||||
from apps.utils.viewsets import CustomGenericViewSet, CustomListModelMixin
|
||||
from rest_framework.permissions import AllowAny
|
||||
|
||||
# Create your views here.
|
||||
class PaperViewSet(CustomGenericViewSet, CustomListModelMixin):
|
||||
queryset = Paper.objects.all()
|
||||
serializer_class = PaperListSerializer
|
||||
filterset_fields = ["publication_year", "type", "fetch_status"]
|
||||
search_fields = ['title', 'first_author', 'first_author_institution']
|
||||
ordering = ["-publication_date", "-create_time"]
|
||||
|
||||
def get_authenticators(self):
|
||||
if self.request.method == 'GET':
|
||||
return []
|
||||
return super().get_authenticators()
|
||||
|
||||
def get_permissions(self):
|
||||
if self.request.method == 'GET':
|
||||
return [AllowAny()]
|
||||
return super().get_permissions()
|
||||
|
|
@ -48,6 +48,7 @@ urlpatterns = [
|
|||
path('', include('apps.wf.urls')),
|
||||
path('', include('apps.utils.urls')),
|
||||
path('', include('apps.ops.urls')),
|
||||
path('', include('apps.resm.urls')),
|
||||
|
||||
# 前端页面入口
|
||||
path('', TemplateView.as_view(template_name="index.html")),
|
||||
|
|
|
|||
Loading…
Reference in New Issue