5 Star 1 Fork 0

Sixsix-it/The tenth power

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
unnamed.patch 5.24 KB
一键复制 编辑 原始数据 按行查看 历史
xwp 提交于 2020-06-03 11:52 . 修改
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"})
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Python
1
https://gitee.com/six_it/The-tenth-power.git
git@gitee.com:six_it/The-tenth-power.git
six_it
The-tenth-power
The tenth power
master

搜索帮助