弹幕接口和历史接口
This commit is contained in:
Generated
+3
-3
@@ -1,8 +1,8 @@
|
|||||||
# 默认忽略的文件
|
# Default ignored files
|
||||||
/shelf/
|
/shelf/
|
||||||
/workspace.xml
|
/workspace.xml
|
||||||
# 基于编辑器的 HTTP 客户端请求
|
|
||||||
/httpRequests/
|
|
||||||
# Datasource local storage ignored files
|
# Datasource local storage ignored files
|
||||||
/dataSources/
|
/dataSources/
|
||||||
/dataSources.local.xml
|
/dataSources.local.xml
|
||||||
|
# 基于编辑器的 HTTP 客户端请求
|
||||||
|
/httpRequests/
|
||||||
|
|||||||
Generated
+28
@@ -0,0 +1,28 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<module type="PYTHON_MODULE" version="4">
|
||||||
|
<component name="FacetManager">
|
||||||
|
<facet type="django" name="Django">
|
||||||
|
<configuration>
|
||||||
|
<option name="rootFolder" value="$MODULE_DIR$" />
|
||||||
|
<option name="settingsModule" value="IT_Show/settings.py" />
|
||||||
|
<option name="manageScript" value="$MODULE_DIR$/manage.py" />
|
||||||
|
<option name="environment" value="<map/>" />
|
||||||
|
<option name="doNotUseTestRunner" value="false" />
|
||||||
|
<option name="trackFilePattern" value="migrations" />
|
||||||
|
</configuration>
|
||||||
|
</facet>
|
||||||
|
</component>
|
||||||
|
<component name="NewModuleRootManager">
|
||||||
|
<content url="file://$MODULE_DIR$" />
|
||||||
|
<orderEntry type="inheritedJdk" />
|
||||||
|
<orderEntry type="sourceFolder" forTests="false" />
|
||||||
|
</component>
|
||||||
|
<component name="TemplatesService">
|
||||||
|
<option name="TEMPLATE_CONFIGURATION" value="Django" />
|
||||||
|
<option name="TEMPLATE_FOLDERS">
|
||||||
|
<list>
|
||||||
|
<option value="$MODULE_DIR$/../IT_Show\templates" />
|
||||||
|
</list>
|
||||||
|
</option>
|
||||||
|
</component>
|
||||||
|
</module>
|
||||||
+55
-8
@@ -1,15 +1,32 @@
|
|||||||
<component name="InspectionProjectProfileManager">
|
<component name="InspectionProjectProfileManager">
|
||||||
<profile version="1.0">
|
<profile version="1.0">
|
||||||
<option name="myName" value="Project Default" />
|
<option name="myName" value="Project Default" />
|
||||||
<inspection_tool class="PyPackageRequirementsInspection" enabled="true" level="WARNING" enabled_by_default="true">
|
<inspection_tool class="DjangoUnresolvedTemplateReferenceInspection" enabled="false" level="WARNING" enabled_by_default="false" />
|
||||||
<option name="ignoredPackages">
|
<inspection_tool class="DuplicatedCode" enabled="true" level="WEAK WARNING" enabled_by_default="true">
|
||||||
<value>
|
<Languages>
|
||||||
<list size="3">
|
<language minSize="309" name="Python" />
|
||||||
<item index="0" class="java.lang.String" itemvalue="Pillow" />
|
</Languages>
|
||||||
<item index="1" class="java.lang.String" itemvalue="PyMySQL" />
|
</inspection_tool>
|
||||||
<item index="2" class="java.lang.String" itemvalue="Django" />
|
<inspection_tool class="JSObsoletePrivateAccessSyntax" enabled="false" level="ERROR" enabled_by_default="false" />
|
||||||
|
<inspection_tool class="PyArgumentListInspection" enabled="false" level="WARNING" enabled_by_default="false" />
|
||||||
|
<inspection_tool class="PyBroadExceptionInspection" enabled="false" level="WEAK WARNING" enabled_by_default="false" />
|
||||||
|
<inspection_tool class="PyPep8Inspection" enabled="true" level="WEAK WARNING" enabled_by_default="true">
|
||||||
|
<option name="ignoredErrors">
|
||||||
|
<list>
|
||||||
|
<option value="E303" />
|
||||||
|
<option value="E128" />
|
||||||
|
<option value="E722" />
|
||||||
|
<option value="E301" />
|
||||||
|
<option value="E501" />
|
||||||
|
<option value="E127" />
|
||||||
|
<option value="E225" />
|
||||||
|
<option value="E129" />
|
||||||
|
<option value="E271" />
|
||||||
|
<option value="E265" />
|
||||||
|
<option value="E262" />
|
||||||
|
<option value="E401" />
|
||||||
|
<option value="W601" />
|
||||||
</list>
|
</list>
|
||||||
</value>
|
|
||||||
</option>
|
</option>
|
||||||
</inspection_tool>
|
</inspection_tool>
|
||||||
<inspection_tool class="PyPep8NamingInspection" enabled="true" level="WEAK WARNING" enabled_by_default="true">
|
<inspection_tool class="PyPep8NamingInspection" enabled="true" level="WEAK WARNING" enabled_by_default="true">
|
||||||
@@ -19,5 +36,35 @@
|
|||||||
</list>
|
</list>
|
||||||
</option>
|
</option>
|
||||||
</inspection_tool>
|
</inspection_tool>
|
||||||
|
<inspection_tool class="PyRedeclarationInspection" enabled="false" level="WARNING" enabled_by_default="false" />
|
||||||
|
<inspection_tool class="PyShadowingBuiltinsInspection" enabled="true" level="WEAK WARNING" enabled_by_default="true">
|
||||||
|
<option name="ignoredNames">
|
||||||
|
<list>
|
||||||
|
<option value="id" />
|
||||||
|
<option value="len" />
|
||||||
|
</list>
|
||||||
|
</option>
|
||||||
|
</inspection_tool>
|
||||||
|
<inspection_tool class="PyShadowingNamesInspection" enabled="false" level="WEAK WARNING" enabled_by_default="false" />
|
||||||
|
<inspection_tool class="PyUnresolvedReferencesInspection" enabled="false" level="WARNING" enabled_by_default="false">
|
||||||
|
<option name="ignoredIdentifiers">
|
||||||
|
<list>
|
||||||
|
<option value="myweb.myapp.models.Message_Board.objects" />
|
||||||
|
<option value="myweb.myapp.models.Student.objects" />
|
||||||
|
<option value="myweb.myapp.models.Content.objects" />
|
||||||
|
<option value="zy2.app1.models.User.objects" />
|
||||||
|
<option value="zy2.app1.models.User.DoesNotExist" />
|
||||||
|
<option value="zy2.app1.models.Post.objects" />
|
||||||
|
<option value="myweb.myapp.models.Student.DoesNotExist" />
|
||||||
|
<option value="urllib.request.method" />
|
||||||
|
<option value="urllib.request.POST" />
|
||||||
|
<option value="urllib.request.is_ajax" />
|
||||||
|
<option value="web.app.models.User.objects" />
|
||||||
|
<option value="web.app.models.User.DoesNotExist" />
|
||||||
|
<option value="web.app.models.Seller.objects" />
|
||||||
|
<option value="web.app.models.Seller.DoesNotExist" />
|
||||||
|
</list>
|
||||||
|
</option>
|
||||||
|
</inspection_tool>
|
||||||
</profile>
|
</profile>
|
||||||
</component>
|
</component>
|
||||||
Generated
+4
-1
@@ -1,4 +1,7 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<project version="4">
|
<project version="4">
|
||||||
<component name="ProjectRootManager" version="2" project-jdk-name="Python 3.9 (it)" project-jdk-type="Python SDK" />
|
<component name="JavaScriptSettings">
|
||||||
|
<option name="languageLevel" value="ES6" />
|
||||||
|
</component>
|
||||||
|
<component name="ProjectRootManager" version="2" project-jdk-name="Python 3.8" project-jdk-type="Python SDK" />
|
||||||
</project>
|
</project>
|
||||||
Generated
+1
-1
@@ -2,7 +2,7 @@
|
|||||||
<project version="4">
|
<project version="4">
|
||||||
<component name="ProjectModuleManager">
|
<component name="ProjectModuleManager">
|
||||||
<modules>
|
<modules>
|
||||||
<module fileurl="file://$PROJECT_DIR$/.idea/it.iml" filepath="$PROJECT_DIR$/.idea/it.iml" />
|
<module fileurl="file://$PROJECT_DIR$/.idea/IT_Show.iml" filepath="$PROJECT_DIR$/.idea/IT_Show.iml" />
|
||||||
</modules>
|
</modules>
|
||||||
</component>
|
</component>
|
||||||
</project>
|
</project>
|
||||||
@@ -0,0 +1,16 @@
|
|||||||
|
"""
|
||||||
|
ASGI config for IT_Show project.
|
||||||
|
|
||||||
|
It exposes the ASGI callable as a module-level variable named ``application``.
|
||||||
|
|
||||||
|
For more information on this file, see
|
||||||
|
https://docs.djangoproject.com/en/3.2/howto/deployment/asgi/
|
||||||
|
"""
|
||||||
|
|
||||||
|
import os
|
||||||
|
|
||||||
|
from django.core.asgi import get_asgi_application
|
||||||
|
|
||||||
|
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'IT_Show.settings')
|
||||||
|
|
||||||
|
application = get_asgi_application()
|
||||||
@@ -0,0 +1,145 @@
|
|||||||
|
"""
|
||||||
|
Django settings for IT_Show project.
|
||||||
|
|
||||||
|
Generated by 'django-admin startproject' using Django 3.2.5.
|
||||||
|
|
||||||
|
For more information on this file, see
|
||||||
|
https://docs.djangoproject.com/en/3.2/topics/settings/
|
||||||
|
|
||||||
|
For the full list of settings and their values, see
|
||||||
|
https://docs.djangoproject.com/en/3.2/ref/settings/
|
||||||
|
"""
|
||||||
|
|
||||||
|
from pathlib import Path
|
||||||
|
import os
|
||||||
|
|
||||||
|
# Build paths inside the project like this: BASE_DIR / 'subdir'.
|
||||||
|
BASE_DIR = Path(__file__).resolve().parent.parent
|
||||||
|
|
||||||
|
|
||||||
|
# Quick-start development settings - unsuitable for production
|
||||||
|
# See https://docs.djangoproject.com/en/3.2/howto/deployment/checklist/
|
||||||
|
|
||||||
|
# SECURITY WARNING: keep the secret key used in production secret!
|
||||||
|
SECRET_KEY = 'django-insecure-f9_1pqmcnv!w0xp#vchj9e06_b-r!ahy@=w__j0^2#w2s)fa-o'
|
||||||
|
|
||||||
|
# SECURITY WARNING: don't run with debug turned on in production!
|
||||||
|
DEBUG = True
|
||||||
|
|
||||||
|
ALLOWED_HOSTS = []
|
||||||
|
|
||||||
|
|
||||||
|
# Application definition
|
||||||
|
|
||||||
|
INSTALLED_APPS = [
|
||||||
|
'django.contrib.admin',
|
||||||
|
'django.contrib.auth',
|
||||||
|
'django.contrib.contenttypes',
|
||||||
|
'django.contrib.sessions',
|
||||||
|
'django.contrib.messages',
|
||||||
|
'django.contrib.staticfiles',
|
||||||
|
'rest_framework',
|
||||||
|
'history',
|
||||||
|
'comments',
|
||||||
|
]
|
||||||
|
|
||||||
|
MIDDLEWARE = [
|
||||||
|
'django.middleware.security.SecurityMiddleware',
|
||||||
|
'django.contrib.sessions.middleware.SessionMiddleware',
|
||||||
|
'django.middleware.common.CommonMiddleware',
|
||||||
|
'django.middleware.csrf.CsrfViewMiddleware',
|
||||||
|
'django.contrib.auth.middleware.AuthenticationMiddleware',
|
||||||
|
'django.contrib.messages.middleware.MessageMiddleware',
|
||||||
|
'django.middleware.clickjacking.XFrameOptionsMiddleware',
|
||||||
|
]
|
||||||
|
|
||||||
|
ROOT_URLCONF = 'IT_Show.urls'
|
||||||
|
|
||||||
|
TEMPLATES = [
|
||||||
|
{
|
||||||
|
'BACKEND': 'django.template.backends.django.DjangoTemplates',
|
||||||
|
'DIRS': [os.path.join(BASE_DIR, 'templates')]
|
||||||
|
,
|
||||||
|
'APP_DIRS': True,
|
||||||
|
'OPTIONS': {
|
||||||
|
'context_processors': [
|
||||||
|
'django.template.context_processors.debug',
|
||||||
|
'django.template.context_processors.request',
|
||||||
|
'django.contrib.auth.context_processors.auth',
|
||||||
|
'django.contrib.messages.context_processors.messages',
|
||||||
|
],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
]
|
||||||
|
|
||||||
|
WSGI_APPLICATION = 'IT_Show.wsgi.application'
|
||||||
|
|
||||||
|
|
||||||
|
# Database
|
||||||
|
# https://docs.djangoproject.com/en/3.2/ref/settings/#databases
|
||||||
|
|
||||||
|
DATABASES = {
|
||||||
|
'default': {
|
||||||
|
'ENGINE': 'django.db.backends.mysql',
|
||||||
|
'NAME': "IT_Show",
|
||||||
|
'PORT': '3306',
|
||||||
|
'PASSWORD': 'Qq2442402635*',
|
||||||
|
'USER': 'root',
|
||||||
|
'HOST': '127.0.0.1'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
# Password validation
|
||||||
|
# https://docs.djangoproject.com/en/3.2/ref/settings/#auth-password-validators
|
||||||
|
|
||||||
|
AUTH_PASSWORD_VALIDATORS = [
|
||||||
|
{
|
||||||
|
'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',
|
||||||
|
},
|
||||||
|
]
|
||||||
|
|
||||||
|
|
||||||
|
# Internationalization
|
||||||
|
# https://docs.djangoproject.com/en/3.2/topics/i18n/
|
||||||
|
|
||||||
|
LANGUAGE_CODE = 'zh-Hans'
|
||||||
|
|
||||||
|
TIME_ZONE = 'Asia/Shanghai'
|
||||||
|
|
||||||
|
USE_I18N = True
|
||||||
|
|
||||||
|
USE_L10N = True
|
||||||
|
|
||||||
|
USE_TZ = False
|
||||||
|
|
||||||
|
|
||||||
|
# Static files (CSS, JavaScript, Images)
|
||||||
|
# https://docs.djangoproject.com/en/3.2/howto/static-files/
|
||||||
|
|
||||||
|
STATIC_URL = '/static/'
|
||||||
|
STATIC_ROOT = os.path.join(BASE_DIR, 'static')
|
||||||
|
MEDIA_URL = '/media/'
|
||||||
|
MEDIA_ROOT = os.path.join(BASE_DIR, 'media')
|
||||||
|
|
||||||
|
|
||||||
|
# Default primary key field type
|
||||||
|
# https://docs.djangoproject.com/en/3.2/ref/settings/#default-auto-field
|
||||||
|
|
||||||
|
DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField'
|
||||||
|
|
||||||
|
REST_FRAMEWORK = {
|
||||||
|
'DEFAULT_RENDERER_CLASSES': ( # 默认响应渲染类
|
||||||
|
'rest_framework.renderers.JSONRenderer', # json渲染器
|
||||||
|
'rest_framework.renderers.BrowsableAPIRenderer', # 浏览API渲染器
|
||||||
|
)
|
||||||
|
}
|
||||||
@@ -0,0 +1,28 @@
|
|||||||
|
"""IT_Show URL Configuration
|
||||||
|
|
||||||
|
The `urlpatterns` list routes URLs to views. For more information please see:
|
||||||
|
https://docs.djangoproject.com/en/3.2/topics/http/urls/
|
||||||
|
Examples:
|
||||||
|
Function views
|
||||||
|
1. Add an import: from my_app import views
|
||||||
|
2. Add a URL to urlpatterns: path('', views.home, name='home')
|
||||||
|
Class-based views
|
||||||
|
1. Add an import: from other_app.views import Home
|
||||||
|
2. Add a URL to urlpatterns: path('', Home.as_view(), name='home')
|
||||||
|
Including another URLconf
|
||||||
|
1. Import the include() function: from django.urls import include, path
|
||||||
|
2. Add a URL to urlpatterns: path('blog/', include('blog.urls'))
|
||||||
|
"""
|
||||||
|
from django.contrib import admin
|
||||||
|
from django.urls import path, include, re_path
|
||||||
|
from django.views.static import serve
|
||||||
|
from IT_Show import settings
|
||||||
|
|
||||||
|
|
||||||
|
urlpatterns = [
|
||||||
|
path('admin/', admin.site.urls),
|
||||||
|
path('api/', include('comments.urls')),
|
||||||
|
path('api/', include('history.urls')),
|
||||||
|
path(r'^api-auth/', include('rest_framework.urls')),
|
||||||
|
re_path(r'^media/(?P<path>.*)', serve, {"document_root": settings.MEDIA_ROOT}),
|
||||||
|
]
|
||||||
@@ -0,0 +1,16 @@
|
|||||||
|
"""
|
||||||
|
WSGI config for IT_Show project.
|
||||||
|
|
||||||
|
It exposes the WSGI callable as a module-level variable named ``application``.
|
||||||
|
|
||||||
|
For more information on this file, see
|
||||||
|
https://docs.djangoproject.com/en/3.2/howto/deployment/wsgi/
|
||||||
|
"""
|
||||||
|
|
||||||
|
import os
|
||||||
|
|
||||||
|
from django.core.wsgi import get_wsgi_application
|
||||||
|
|
||||||
|
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'IT_Show.settings')
|
||||||
|
|
||||||
|
application = get_wsgi_application()
|
||||||
@@ -0,0 +1,5 @@
|
|||||||
|
from django.contrib import admin
|
||||||
|
from .models import Comments
|
||||||
|
# Register your models here.
|
||||||
|
|
||||||
|
admin.site.register(Comments)
|
||||||
@@ -0,0 +1,6 @@
|
|||||||
|
from django.apps import AppConfig
|
||||||
|
|
||||||
|
|
||||||
|
class CommentsConfig(AppConfig):
|
||||||
|
default_auto_field = 'django.db.models.BigAutoField'
|
||||||
|
name = 'comments'
|
||||||
@@ -0,0 +1,22 @@
|
|||||||
|
# Generated by Django 3.2.5 on 2022-04-15 14:15
|
||||||
|
|
||||||
|
from django.db import migrations, models
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
initial = True
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.CreateModel(
|
||||||
|
name='Comments',
|
||||||
|
fields=[
|
||||||
|
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
|
||||||
|
('post_time', models.DateTimeField(verbose_name='发布时间')),
|
||||||
|
('content', models.CharField(max_length=50, verbose_name='弹幕内容')),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
]
|
||||||
@@ -0,0 +1,11 @@
|
|||||||
|
from django.db import models
|
||||||
|
|
||||||
|
# Create your models here.
|
||||||
|
|
||||||
|
|
||||||
|
class Comments(models.Model):
|
||||||
|
post_time = models.DateTimeField(verbose_name="发布时间")
|
||||||
|
content = models.CharField(verbose_name="弹幕内容", max_length=50, blank=False)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@@ -0,0 +1,25 @@
|
|||||||
|
from rest_framework import serializers
|
||||||
|
from .models import *
|
||||||
|
|
||||||
|
|
||||||
|
class CommentsInfo(serializers.ModelSerializer):
|
||||||
|
class Meta:
|
||||||
|
model = Comments
|
||||||
|
fields = ['content', 'post_time']
|
||||||
|
|
||||||
|
post_time = serializers.DateTimeField(label="发布时间", required=False)
|
||||||
|
content = serializers.CharField(label="弹幕内容", max_length=50, required=True)
|
||||||
|
|
||||||
|
def validate_content(self, value):
|
||||||
|
ban = ['!', '@', '#', '$', '%', '^', '&', '*', '(', ')', "_", "-"]
|
||||||
|
for i in ban:
|
||||||
|
if i in value:
|
||||||
|
raise serializers.ValidationError('非法字符')
|
||||||
|
|
||||||
|
if len(value) > 50:
|
||||||
|
raise serializers.ValidationError("弹幕过长")
|
||||||
|
elif len(value) == 0:
|
||||||
|
raise serializers.ValidationError("输入不能为空")
|
||||||
|
|
||||||
|
|
||||||
|
return value
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
from django.test import TestCase
|
||||||
|
|
||||||
|
# Create your tests here.
|
||||||
@@ -0,0 +1,9 @@
|
|||||||
|
from django.contrib import admin
|
||||||
|
from django.urls import path
|
||||||
|
from . import views
|
||||||
|
|
||||||
|
urlpatterns = [
|
||||||
|
path('comment/', views.comments.as_view()),
|
||||||
|
]
|
||||||
|
|
||||||
|
|
||||||
@@ -0,0 +1,45 @@
|
|||||||
|
import time, datetime
|
||||||
|
from django.conf import settings
|
||||||
|
import re
|
||||||
|
from django.shortcuts import render
|
||||||
|
from rest_framework.views import APIView
|
||||||
|
from rest_framework.response import Response
|
||||||
|
from .models import *
|
||||||
|
from .serializers import CommentsInfo
|
||||||
|
from django.utils import timezone
|
||||||
|
# Create your views here.
|
||||||
|
|
||||||
|
|
||||||
|
class comments(APIView):
|
||||||
|
|
||||||
|
def get(self, request):
|
||||||
|
data = {}
|
||||||
|
queryset = Comments.objects.all()
|
||||||
|
serializer = CommentsInfo(queryset, many=True)
|
||||||
|
try:
|
||||||
|
data['data'] = serializer.data
|
||||||
|
except:
|
||||||
|
data['msg'] = serializer.error_messages
|
||||||
|
if len(data['data']) == 0:
|
||||||
|
data['msg'] = 'error'
|
||||||
|
data['code'] = "40000"
|
||||||
|
else:
|
||||||
|
data['msg'] = "success"
|
||||||
|
data['code'] = "20000"
|
||||||
|
return Response(data=data)
|
||||||
|
|
||||||
|
|
||||||
|
def post(self, request):
|
||||||
|
data = {}
|
||||||
|
serializer = CommentsInfo(data=request.data)
|
||||||
|
if not serializer.is_valid(raise_exception=True):
|
||||||
|
data['msg'] = serializer.error_messages
|
||||||
|
data['code'] = "40000"
|
||||||
|
return Response(data=data)
|
||||||
|
serializer.validated_data['post_time'] = timezone.now().replace(microsecond=0)
|
||||||
|
serializer.save()
|
||||||
|
data['data'] = serializer.validated_data
|
||||||
|
data['msg'] = "success"
|
||||||
|
data['code'] = "20000"
|
||||||
|
return Response(data=data)
|
||||||
|
|
||||||
@@ -0,0 +1,5 @@
|
|||||||
|
from django.contrib import admin
|
||||||
|
from .models import History
|
||||||
|
# Register your models here.
|
||||||
|
|
||||||
|
admin.site.register(History)
|
||||||
@@ -0,0 +1,6 @@
|
|||||||
|
from django.apps import AppConfig
|
||||||
|
|
||||||
|
|
||||||
|
class HistoryConfig(AppConfig):
|
||||||
|
default_auto_field = 'django.db.models.BigAutoField'
|
||||||
|
name = 'history'
|
||||||
@@ -0,0 +1,24 @@
|
|||||||
|
# Generated by Django 3.2.5 on 2022-04-15 14:20
|
||||||
|
|
||||||
|
from django.db import migrations, models
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
initial = True
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.CreateModel(
|
||||||
|
name='History',
|
||||||
|
fields=[
|
||||||
|
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
|
||||||
|
('grade', models.IntegerField(verbose_name='年份')),
|
||||||
|
('name', models.CharField(max_length=30, verbose_name='事件名称')),
|
||||||
|
('description', models.CharField(max_length=200, verbose_name='事件描述')),
|
||||||
|
('img', models.ImageField(upload_to='', verbose_name='图片')),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
]
|
||||||
@@ -0,0 +1,18 @@
|
|||||||
|
# Generated by Django 3.2.5 on 2022-04-15 14:32
|
||||||
|
|
||||||
|
from django.db import migrations, models
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('history', '0001_initial'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.AlterField(
|
||||||
|
model_name='history',
|
||||||
|
name='img',
|
||||||
|
field=models.ImageField(upload_to='image', verbose_name='图片'),
|
||||||
|
),
|
||||||
|
]
|
||||||
@@ -0,0 +1,18 @@
|
|||||||
|
# Generated by Django 3.2.5 on 2022-04-15 23:05
|
||||||
|
|
||||||
|
from django.db import migrations, models
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('history', '0002_alter_history_img'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.AlterField(
|
||||||
|
model_name='history',
|
||||||
|
name='img',
|
||||||
|
field=models.ImageField(upload_to='', verbose_name='图片'),
|
||||||
|
),
|
||||||
|
]
|
||||||
@@ -0,0 +1,11 @@
|
|||||||
|
from django.db import models
|
||||||
|
|
||||||
|
# Create your models here.
|
||||||
|
|
||||||
|
|
||||||
|
class History(models.Model):
|
||||||
|
grade = models.IntegerField(verbose_name="年份")
|
||||||
|
name = models.CharField(verbose_name="事件名称", max_length=30)
|
||||||
|
description = models.CharField(verbose_name="事件描述", max_length=200)
|
||||||
|
img = models.ImageField(verbose_name="图片", upload_to="image")
|
||||||
|
|
||||||
@@ -0,0 +1,19 @@
|
|||||||
|
from rest_framework import serializers
|
||||||
|
from .models import *
|
||||||
|
|
||||||
|
|
||||||
|
class HistoryInfoSerializer(serializers.ModelSerializer):
|
||||||
|
class Meta:
|
||||||
|
model = History
|
||||||
|
fields = '__all__'
|
||||||
|
grade = serializers.CharField(label="年级", required=True)
|
||||||
|
name = serializers.CharField(label="事件名称", max_length=30, required=True)
|
||||||
|
description = serializers.CharField(label="事件描述", max_length=200, required=True)
|
||||||
|
img = serializers.ImageField(label="图片", required=False)
|
||||||
|
|
||||||
|
def validate_grade(self, value):
|
||||||
|
if not (2010 < value <= 2021):
|
||||||
|
raise serializers.ValidationError("不合法输入")
|
||||||
|
return value
|
||||||
|
|
||||||
|
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
from django.test import TestCase
|
||||||
|
|
||||||
|
# Create your tests here.
|
||||||
@@ -0,0 +1,11 @@
|
|||||||
|
from django.contrib import admin
|
||||||
|
from django.urls import path
|
||||||
|
from . import views
|
||||||
|
from django.conf.urls.static import static
|
||||||
|
from IT_Show import settings
|
||||||
|
|
||||||
|
urlpatterns = [
|
||||||
|
path('history/', views.history.as_view()),
|
||||||
|
]
|
||||||
|
|
||||||
|
urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
|
||||||
@@ -0,0 +1,37 @@
|
|||||||
|
import time
|
||||||
|
from django.conf import settings
|
||||||
|
import re
|
||||||
|
from django.shortcuts import render
|
||||||
|
from rest_framework.views import APIView
|
||||||
|
from rest_framework.response import Response
|
||||||
|
from .models import History
|
||||||
|
from .serializers import HistoryInfoSerializer
|
||||||
|
# Create your views here.
|
||||||
|
|
||||||
|
|
||||||
|
class history(APIView):
|
||||||
|
|
||||||
|
def get(self, request):
|
||||||
|
key = []
|
||||||
|
data = {"data": key}
|
||||||
|
for i in range(2012, 2022):
|
||||||
|
temp = {}
|
||||||
|
try:
|
||||||
|
works_set = History.objects.filter(grade=i)
|
||||||
|
if works_set:
|
||||||
|
serializer = HistoryInfoSerializer(works_set, many=True)
|
||||||
|
temp['grade'] = i
|
||||||
|
temp['data'] = serializer.data
|
||||||
|
data['data'].append(temp)
|
||||||
|
except Exception:
|
||||||
|
pass
|
||||||
|
if len(data['data']) == 0:
|
||||||
|
data['code'] = 40000
|
||||||
|
data['msg'] = "error"
|
||||||
|
else:
|
||||||
|
data['code'] = 20000
|
||||||
|
data['msg'] = 'success'
|
||||||
|
return Response(data=data)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
Binary file not shown.
|
After Width: | Height: | Size: 81 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 720 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 768 KiB |
Reference in New Issue
Block a user