代码拉取完成,页面将自动刷新
Index: tenth_power/tenth_power/apps/ElroyDn/urls.py
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
--- tenth_power/tenth_power/apps/ElroyDn/urls.py (revision )
+++ tenth_power/tenth_power/apps/ElroyDn/urls.py (revision 2cca880ca1f6864afc860882c716805cd2fe6ab1)
@@ -2,10 +2,4 @@
from . import views
urlpatterns = [
- re_path(r"^questions/$", views.QuestionCreateAPIView.as_view()),
- re_path(r"^labels/$", views.LabelsAPIView.as_view()),
- re_path(r"^questions/(?P<pk>-?[1-9]\d*)/label/wait/$", views.aaa.as_view()),
- re_path(r"^questions/(?P<pk>-?[1-9]\d*)/label/hot/$", views.bbb.as_view()),
- re_path(r"^questions/(?P<pk>-?[1-9]\d*)/label/new/$", views.NewAPIView.as_view()),
-
]
Index: tenth_power/tenth_power/apps/ElroyDn/serializer.py
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
--- tenth_power/tenth_power/apps/ElroyDn/serializer.py (revision )
+++ tenth_power/tenth_power/apps/ElroyDn/serializer.py (revision )
@@ -1,49 +0,0 @@
-from rest_framework import serializers
-from xyz.models import Question, Label, Reply, User
-
-
-# 所有标签
-class LabelSerializer(serializers.ModelSerializer):
- class Meta:
- model = Label
- fields = ['id', 'label_name']
-
-
-# 发布问题
-class QuestionSerializer(serializers.ModelSerializer):
- user = serializers.PrimaryKeyRelatedField(read_only=True)
-
- class Meta:
- model = Question
- fields = '__all__'
-
-
-# 等待回答
-class AwaitSerializer(serializers.ModelSerializer):
- labels = serializers.StringRelatedField(many=True)
- user = serializers.StringRelatedField()
-
- class Meta:
- model = Question
- fields = '__all__'
- # exclude=['labels']
-
-
-# 热门回答
-class HotSerializer(serializers.ModelSerializer):
- labels = serializers.StringRelatedField(label='标签名', many=True)
- user = serializers.StringRelatedField()
-
- class Meta:
- model = Question
- exclude = ['content', 'solve', 'thumbup', 'updatetime']
-
-
-# 最新回答
-class NewSerializer(serializers.ModelSerializer):
- labels = serializers.StringRelatedField(label='标签名', many=True)
- user = serializers.StringRelatedField()
-
- class Meta:
- model = Question
- exclude = ['content', 'solve', 'thumbup', 'updatetime']
Index: tenth_power/tenth_power/apps/ElroyDn/views.py
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
--- tenth_power/tenth_power/apps/ElroyDn/views.py (revision )
+++ tenth_power/tenth_power/apps/ElroyDn/views.py (revision 2cca880ca1f6864afc860882c716805cd2fe6ab1)
@@ -1,76 +1,3 @@
from django.shortcuts import render
# Create your views here.
-# Create your views here.
-
-from rest_framework.generics import CreateAPIView, ListAPIView
-
-from rest_framework.views import APIView
-from ElroyDn.serializer import QuestionSerializer, LabelSerializer, AwaitSerializer, HotSerializer, NewSerializer
-from rest_framework.response import Response
-from xyz.models import Question, Label
-
-
-# 所有标签
-class LabelsAPIView(APIView):
- def get(self, request):
- labels = Label.objects.all()
- serializer = LabelSerializer(labels, many=True)
- return Response(serializer.data)
-
-
-# 等待回答
-
-class aaa(APIView):
- def get(self, request, pk):
- if pk == "-1":
- question = Question.objects.filter(reply=0)
- serializer = AwaitSerializer(question, many=True)
- else:
- question = Question.objects.get(id=pk)
- serializer = AwaitSerializer(question)
- return Response(serializer.data)
-
-
-# 热门回答
-
-class bbb(APIView):
- def get(self, request, pk):
- if pk == "-1":
- question = Question.objects.all().order_by('-visits')
- serializer = HotSerializer(question, many=True)
- else:
- question = Question.objects.get(id=pk)
- serializer = HotSerializer(question)
- return Response(serializer.data)
-
-
-# 最新回答
-class NewAPIView(APIView):
- def get(self, request, pk):
- if pk == "-1":
- question = Question.objects.all().order_by('-createtime')
- serializer = NewSerializer(question, many=True)
- else:
- question = Question.objects.get(id=pk)
- serializer = NewSerializer(question)
- return Response(serializer.data)
-
-
-# 发布问题
-class QuestionCreateAPIView(CreateAPIView):
- queryset = Question
- serializer_class = QuestionSerializer
-
- def create(self, request, *args, **kwargs):
- create_data = request.data
- user = request.user.id
- create_data['user'] = user
- title = create_data.get('title')
- content = create_data.get('content')
- labels1 = create_data.get('labels')
- for i in labels1:
- labels2 = i
- question = Question.objects.create(content=content, title=title, user_id=user)
- question.labels.add(labels2)
- return Response({"message": "问题发布成功", "success": "True"})
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。