diff --git a/.gitignore b/.gitignore index 403adbc..48019c7 100644 --- a/.gitignore +++ b/.gitignore @@ -1,7 +1,8 @@ .DS_Store node_modules /dist - +.idea +__pycache__ # local env files .env.local diff --git a/TP_Admin/__pycache__/__init__.cpython-37.pyc b/TP_Admin/__pycache__/__init__.cpython-37.pyc deleted file mode 100644 index 5b2bc4a..0000000 Binary files a/TP_Admin/__pycache__/__init__.cpython-37.pyc and /dev/null differ diff --git a/TP_Admin/__pycache__/settings.cpython-37.pyc b/TP_Admin/__pycache__/settings.cpython-37.pyc deleted file mode 100644 index 1897621..0000000 Binary files a/TP_Admin/__pycache__/settings.cpython-37.pyc and /dev/null differ diff --git a/TP_Admin/__pycache__/wsgi.cpython-37.pyc b/TP_Admin/__pycache__/wsgi.cpython-37.pyc deleted file mode 100644 index 1bf2e0b..0000000 Binary files a/TP_Admin/__pycache__/wsgi.cpython-37.pyc and /dev/null differ diff --git a/TP_Admin/__init__.py b/TP_Api/__init__.py similarity index 100% rename from TP_Admin/__init__.py rename to TP_Api/__init__.py diff --git a/TP_Admin/asgi.py b/TP_Api/asgi.py similarity index 73% rename from TP_Admin/asgi.py rename to TP_Api/asgi.py index 499eb58..4d2c0ee 100644 --- a/TP_Admin/asgi.py +++ b/TP_Api/asgi.py @@ -1,5 +1,5 @@ """ -ASGI config for TP_Admin project. +ASGI config for TP_Api project. It exposes the ASGI callable as a module-level variable named ``application``. @@ -11,6 +11,6 @@ import os from django.core.asgi import get_asgi_application -os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'TP_Admin.settings') +os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'TP_Api.settings') application = get_asgi_application() diff --git a/TP_Admin/settings.py b/TP_Api/settings.py similarity index 72% rename from TP_Admin/settings.py rename to TP_Api/settings.py index 3b12108..5a2a2af 100644 --- a/TP_Admin/settings.py +++ b/TP_Api/settings.py @@ -1,5 +1,5 @@ """ -Django settings for TP_Admin project. +Django settings for TP_Api project. Generated by 'django-admin startproject' using Django 3.2.19. @@ -11,6 +11,7 @@ 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 @@ -20,12 +21,12 @@ BASE_DIR = Path(__file__).resolve().parent.parent # 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-d@xkg+%-m3g_h!%howm1%u#1l*v&sd3=7&_-33w!(oy7#!hg79' +SECRET_KEY = 'django-insecure-kqm6r(-!q-emw5c!!@dc)9l^hm@m#4!)-d7ecq85&u^5leu5)_' # SECURITY WARNING: don't run with debug turned on in production! -DEBUG = True +DEBUG = False -ALLOWED_HOSTS = [] +ALLOWED_HOSTS = ["*"] # Application definition @@ -37,26 +38,29 @@ INSTALLED_APPS = [ 'django.contrib.sessions', 'django.contrib.messages', 'django.contrib.staticfiles', - 'app.apps.AppConfig', + 'rest_framework', + 'django_filters', + 'corsheaders', + 'app' ] MIDDLEWARE = [ 'django.middleware.security.SecurityMiddleware', 'django.contrib.sessions.middleware.SessionMiddleware', + 'corsheaders.middleware.CorsMiddleware', 'django.middleware.common.CommonMiddleware', - 'django.middleware.csrf.CsrfViewMiddleware', + # 'django.middleware.csrf.CsrfViewMiddleware', 'django.contrib.auth.middleware.AuthenticationMiddleware', 'django.contrib.messages.middleware.MessageMiddleware', 'django.middleware.clickjacking.XFrameOptionsMiddleware', ] -ROOT_URLCONF = 'TP_Admin.urls' +ROOT_URLCONF = 'TP_Api.urls' TEMPLATES = [ { 'BACKEND': 'django.template.backends.django.DjangoTemplates', - 'DIRS': [BASE_DIR / 'templates'] - , + 'DIRS': [], 'APP_DIRS': True, 'OPTIONS': { 'context_processors': [ @@ -69,7 +73,7 @@ TEMPLATES = [ }, ] -WSGI_APPLICATION = 'TP_Admin.wsgi.application' +WSGI_APPLICATION = 'TP_Api.wsgi.application' # Database @@ -105,15 +109,15 @@ AUTH_PASSWORD_VALIDATORS = [ # Internationalization # https://docs.djangoproject.com/en/3.2/topics/i18n/ -LANGUAGE_CODE = 'en-us' +LANGUAGE_CODE = 'zh-hans' -TIME_ZONE = 'UTC' +TIME_ZONE = 'Asia/Shanghai' USE_I18N = True USE_L10N = True -USE_TZ = True +USE_TZ = False # Static files (CSS, JavaScript, Images) @@ -121,7 +125,37 @@ USE_TZ = True STATIC_URL = '/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' + +# 解决跨域 +CORS_ALLOW_CREDENTIALS = True +CORS_ORIGIN_ALLOW_ALL = True +CORS_ALLOW_HEADERS = ["*"] + +CORS_ORIGIN_WHITELIST = () +# 对应的发送的请求的跨域 +CORS_ALLOW_METHODS = ( + 'DELETE', + 'GET', + 'OPTIONS', + 'PATCH', + 'POST', + 'PUT', + 'VIEW', +) + +USE_L10N = False +DATE_FORMAT = 'Y-m-d' +DATETIME_FORMAT = 'Y-m-d H:M:S' + +REST_FRAMEWORK = { + 'DATETIME_FORMAT': "%Y-%m-%d %H:%M:%S", + 'DATE_FORMAT': "%Y-%m-%d", + 'DEFAULT_FILTER_BACKENDS': ['django_filters.rest_framework.DjangoFilterBackend'], +} \ No newline at end of file diff --git a/TP_Admin/__pycache__/urls.cpython-37.pyc b/TP_Api/urls.py similarity index 57% rename from TP_Admin/__pycache__/urls.cpython-37.pyc rename to TP_Api/urls.py index 86d2b0e..6c2d041 100644 Binary files a/TP_Admin/__pycache__/urls.cpython-37.pyc and b/TP_Api/urls.py differ diff --git a/TP_Admin/wsgi.py b/TP_Api/wsgi.py similarity index 73% rename from TP_Admin/wsgi.py rename to TP_Api/wsgi.py index 1ea9980..6ce5333 100644 --- a/TP_Admin/wsgi.py +++ b/TP_Api/wsgi.py @@ -1,5 +1,5 @@ """ -WSGI config for TP_Admin project. +WSGI config for TP_Api project. It exposes the WSGI callable as a module-level variable named ``application``. @@ -11,6 +11,6 @@ import os from django.core.wsgi import get_wsgi_application -os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'TP_Admin.settings') +os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'TP_Api.settings') application = get_wsgi_application() diff --git a/TP后台接口文档.md b/TP后台接口文档.md new file mode 100644 index 0000000..0ee9fc8 --- /dev/null +++ b/TP后台接口文档.md @@ -0,0 +1,240 @@ + + + + + + +# TP后台接口文档 +
+条件查询 + +- 请求方式:GET + +- 请求链接:http://127.0.0.1:8002/api/ + +- 请求参数: + + | 参数名 | 参数值 | 是否必填 | 参数类型 | 描述说明 | + | ----------- |---------------------| -------- |--------| ---------- | + | record_time | 2023-05-26 13:09:05 | 否 | string | 记录仪时间 | + | police_id | 00000001 | 否 | string | 警号 | + | event_type | 0 | 否 | string | 事件类型 | + +- 可选参数: + + | 参数名 | 参数值 | 是否必填 | 参数类型 | 描述说明 | + | --------- | ------ | -------- | -------- | -------------------- | + | page | 1 | 否 | string | 页码 | + | page_size | 20 | 否 | string | 页面大小(每页条数) | + +- 返回值: + + | 参数名 | 参数值 | 参数类型 | 描述说明 | + | ------------- | ------------------------------------------------- | -------- | ------------------------ | + | uid | 1 | int | 自增 | + | video_hash | 38fb463b135fa12534104f85492cc6f1 | string | 视频哈希值 | + | record_time | 2023-05-26 13:09:05 | string | 记录仪时间 | + | police_id | 00000001 | string | 警号 | + | event_type | 1 | string | 事件类型 | + | is_violation | true | bool | 是否违规 | + | small_image | http://192.168.0.47:8000/media/images/0000609.jpg | string | 缩略图 | + | relative_time | 4.0 | float | 相对时间 | + | video_dir | http://192.168.0.47:8000/media/video/B1.MP4 | string | 视频地址 | + | car_number | 苏a045689 | string | 车牌号 | + | ai_analysis | 违规 | string | 分析结果 | + | add_time | 2023-05-31 18:42:15 | string | 记录添加时间(自动添加) | + | update_time | 2023-05-31 18:42:15 | string | 记录更新时间(自动添加) | + | is_display | true | bool | 是否展示(自动添加) | + + + + +
+ +
+查询所有 + +- 请求方式:GET + +- 请求链接:http://127.0.0.1:8002/api/ + +- 可选参数: + + | 参数名 | 参数值 | 是否必填 | 参数类型 | 描述说明 | + | --------- | ------ | -------- | -------- | -------------------- | + | page | 1 | 否 | string | 页码 | + | page_size | 20 | 否 | string | 页面大小(每页条数) | + +- 返回值 + + | 参数名 | 参数值 | 参数类型 | 描述说明 | + | ------------- | ------------------------------------------------- | -------- | ------------------------ | + | uid | 1 | int | 自增 | + | video_hash | 38fb463b135fa12534104f85492cc6f1 | string | 视频哈希值 | + | record_time | 2023-05-26 13:09:05 | string | 记录仪时间 | + | police_id | 00000001 | string | 警号 | + | event_type | 1 | string | 事件类型 | + | is_violation | true | bool | 是否违规 | + | small_image | http://192.168.0.47:8000/media/images/0000609.jpg | string | 缩略图 | + | relative_time | 4.0 | float | 相对时间 | + | video_dir | http://192.168.0.47:8000/media/video/B1.MP4 | string | 视频地址 | + | car_number | 苏a045689 | string | 车牌号 | + | ai_analysis | 违规 | string | 分析结果 | + | add_time | 2023-05-31 18:42:15 | string | 记录添加时间(自动添加) | + | update_time | 2023-05-31 18:42:15 | string | 记录更新时间(自动添加) | + | is_display | true | bool | 是否展示(自动添加) | + + +
+ +
+新增数据 + +- 请求方式:POST + +- 请求链接:http://127.0.0.1:8002/api/ + +- 请求body: + + ```json + { + "video_hash": "vbhdrbvcw", + "record_time": "2023-05-26 13:09:05", + "police_id": "00000002", + "event_type": "1", + "is_violation": true, + "small_image": "nvikefrooiwer", + "relative_time": 4.0, + "video_dir": "/d/test", + "car_number": "苏a045689", + "ai_analysis": "违规" + } + ``` + + | 参数名 | 参数值 | 是否必填 | 参数类型 | 描述说明 | + | ------------- |---------------------| -------- |----------| ------ | +| video_hash | vbhdrbvcw | 是 | string | 视频哈希 | + | record_time | 2023-05-26 13:09:05 | 是 | datetime | 记录仪时间 | + | police_id | 00000002 | 是 | string | 警号 | + | event_type | 1 | 是 | string | 事件类型 | + | is_violation | true | 是 | bool | 是否违规 | + | small_image | nvikefrooiwer | 是 | string | 缩略图 | + | relative_time | 4.0 | 是 | int | 相对时间 | + | video_dir | /d/test | 是 | string | 视频路径 | + | car_number | 苏a045689 | 是 | string | 车牌号 | + | ai_analysis | 违规 | 是 | string | 分析结果 | + +- 返回值 + + | 参数名 | 参数值 | 参数类型 | 描述说明 | + | ------------- | ------------------------------------------------- | -------- | ------------------------ | + | uid | 1 | int | 自增 | + | video_hash | 38fb463b135fa12534104f85492cc6f1 | string | 视频哈希值 | + | record_time | 2023-05-26 13:09:05 | string | 记录仪时间 | + | police_id | 00000001 | string | 警号 | + | event_type | 1 | string | 事件类型 | + | is_violation | true | bool | 是否违规 | + | small_image | http://192.168.0.47:8000/media/images/0000609.jpg | string | 缩略图 | + | relative_time | 4.0 | float | 相对时间 | + | video_dir | http://192.168.0.47:8000/media/video/B1.MP4 | string | 视频地址 | + | car_number | 苏a045689 | string | 车牌号 | + | ai_analysis | 违规 | string | 分析结果 | + | add_time | 2023-05-31 18:42:15 | string | 记录添加时间(自动添加) | + | update_time | 2023-05-31 18:42:15 | string | 记录更新时间(自动添加) | + | is_display | true | bool | 是否展示(自动添加) | + + +
+ +
+修改数据 + +- 请求方式:put + +- 请求链接:http://127.0.0.1:8002/api/20/ + +- 请求body: + + ```json + { + "video_hash": "vbhdrbvcw", + "record_time": "2023-05-26 13:09:05", + "police_id": "00000002", + "event_type": "1", + "is_violation": true, + "small_image": "nvikefrooiwer", + "relative_time": 4.0, + "video_dir": "/d/test", + "car_number": "苏a045689", + "ai_analysis": "违规" + } + ``` + + | 参数名 | 参数值 | 是否必填 | 参数类型 | 描述说明 | + | ------------- |---------------------| -------- |-----|-------| +| video_hash | vbhdrbvcw | 是 | string | 视频哈希 | + | record_time | 2023-05-26 13:09:05 | 是 | string | 记录仪时间 | + | police_id | 00000002 | 是 | string | 警号 | + | event_type | 1 | 是 | string | 事件类型 | + | is_violation | true | 是 | bool | 是否违规 | + | small_image | nvikefrooiwer | 是 | string | 缩略图 | + | relative_time | 4.0 | 是 | float | 相对时间 | + | video_dir | /d/test | 是 | string | 视频路径 | + | car_number | 苏a045689 | 是 | string | 车牌号 | + | ai_analysis | 违规 | 是 | string | 分析结果 | + +- 备注:操作会修改uid为20的数据 + +- 返回值: + + | 参数名 | 参数值 | 参数类型 | 描述说明 | + | ------------- | ------------------------------------------------- | -------- | ---------------------- | + | uid | 1 | int | 自增 | + | video_hash | 38fb463b135fa12534104f85492cc6f1 | string | 视频哈希值 | + | record_time | 2023-05-26 13:09:05 | string | 记录仪时间 | + | police_id | 00000001 | string | 警号 | + | event_type | 1 | string | 事件类型 | + | is_violation | true | bool | 是否违规 | + | small_image | http://192.168.0.47:8000/media/images/0000609.jpg | string | 缩略图 | + | relative_time | 4.0 | float | 相对时间 | + | video_dir | http://192.168.0.47:8000/media/video/B1.MP4 | string | 视频地址 | + | car_number | 苏a045689 | string | 车牌号 | + | ai_analysis | 违规 | string | 分析结果 | + | add_time | 2023-05-31 18:42:15 | string | 记录添加时间(自动添加) | + | update_time | 2023-05-31 18:42:15 | string | 记录更新时间(自动添加) | + | is_display | true | bool | 是否展示(自动添加) | + + +
+ +
+ +删除数据 + +- 请求方式:delete + +- 请求链接:http://127.0.0.1:8002/api/20/ + +- 备注:操作会删除uid为20的数据 + +- 返回值: + + | 参数名 | 参数值 | 参数类型 | 描述说明 | + | ------------- | ------------------------------------------------- | -------- | ------------------------ | + | uid | 1 | int | 自增 | + | video_hash | 38fb463b135fa12534104f85492cc6f1 | string | 视频哈希值 | + | record_time | 2023-05-26 13:09:05 | string | 记录仪时间 | + | police_id | 00000001 | string | 警号 | + | event_type | 1 | string | 事件类型 | + | is_violation | true | bool | 是否违规 | + | small_image | http://192.168.0.47:8000/media/images/0000609.jpg | string | 缩略图 | + | relative_time | 4.0 | float | 相对时间 | + | video_dir | http://192.168.0.47:8000/media/video/B1.MP4 | string | 视频地址 | + | car_number | 苏a045689 | string | 车牌号 | + | ai_analysis | 违规 | string | 分析结果 | + | add_time | 2023-05-31 18:42:15 | string | 记录添加时间(自动添加) | + | update_time | 2023-05-31 18:42:15 | string | 记录更新时间(自动添加) | + | is_display | true | bool | 是否展示(自动添加) | + + +
diff --git a/app/__pycache__/__init__.cpython-37.pyc b/app/__pycache__/__init__.cpython-37.pyc deleted file mode 100644 index 4cab709..0000000 Binary files a/app/__pycache__/__init__.cpython-37.pyc and /dev/null differ diff --git a/app/__pycache__/admin.cpython-37.pyc b/app/__pycache__/admin.cpython-37.pyc deleted file mode 100644 index 49d1dbe..0000000 Binary files a/app/__pycache__/admin.cpython-37.pyc and /dev/null differ diff --git a/app/__pycache__/apps.cpython-37.pyc b/app/__pycache__/apps.cpython-37.pyc deleted file mode 100644 index c8b0412..0000000 Binary files a/app/__pycache__/apps.cpython-37.pyc and /dev/null differ diff --git a/app/__pycache__/models.cpython-37.pyc b/app/__pycache__/models.cpython-37.pyc deleted file mode 100644 index a3b3001..0000000 Binary files a/app/__pycache__/models.cpython-37.pyc and /dev/null differ diff --git a/app/apps.py b/app/apps.py index ed327d2..ab972ce 100644 --- a/app/apps.py +++ b/app/apps.py @@ -1,6 +1,6 @@ from django.apps import AppConfig -class AppConfig(AppConfig): +class App01Config(AppConfig): default_auto_field = 'django.db.models.BigAutoField' name = 'app' diff --git a/app/migrations/0001_initial.py b/app/migrations/0001_initial.py new file mode 100644 index 0000000..e6709aa --- /dev/null +++ b/app/migrations/0001_initial.py @@ -0,0 +1,30 @@ +# Generated by Django 3.2.19 on 2023-05-25 08:07 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + initial = True + + dependencies = [ + ] + + operations = [ + migrations.CreateModel( + name='MyModel', + fields=[ + ('uid', models.AutoField(primary_key=True, serialize=False)), + ('video_hash', models.CharField(max_length=50)), + ('record_time', models.DateTimeField()), + ('police_id', models.CharField(max_length=50)), + ('event_type', models.IntegerField()), + ('is_violation', models.BooleanField()), + ('small_image', models.CharField(max_length=50)), + ('relative_time', models.IntegerField()), + ('video_dir', models.CharField(max_length=50)), + ('car_number', models.CharField(max_length=50)), + ('ai_analysis', models.CharField(max_length=50)), + ], + ), + ] diff --git a/app/migrations/0002_auto_20230526_1003.py b/app/migrations/0002_auto_20230526_1003.py new file mode 100644 index 0000000..8a62cd8 --- /dev/null +++ b/app/migrations/0002_auto_20230526_1003.py @@ -0,0 +1,23 @@ +# Generated by Django 3.2.19 on 2023-05-26 10:03 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('app', '0001_initial'), + ] + + operations = [ + migrations.AlterField( + model_name='mymodel', + name='ai_analysis', + field=models.CharField(max_length=255), + ), + migrations.AlterField( + model_name='mymodel', + name='relative_time', + field=models.FloatField(), + ), + ] diff --git a/app/migrations/0003_auto_20230529_1446.py b/app/migrations/0003_auto_20230529_1446.py new file mode 100644 index 0000000..91603ed --- /dev/null +++ b/app/migrations/0003_auto_20230529_1446.py @@ -0,0 +1,35 @@ +# Generated by Django 3.2.19 on 2023-05-29 14:46 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('app', '0002_auto_20230526_1003'), + ] + + operations = [ + migrations.CreateModel( + name='TP_Api', + fields=[ + ('uid', models.AutoField(primary_key=True, serialize=False)), + ('video_hash', models.CharField(max_length=50)), + ('record_time', models.DateTimeField()), + ('police_id', models.CharField(max_length=50)), + ('event_type', models.IntegerField()), + ('is_violation', models.BooleanField()), + ('small_image', models.CharField(max_length=50)), + ('relative_time', models.FloatField()), + ('video_dir', models.CharField(max_length=50)), + ('car_number', models.CharField(max_length=50)), + ('ai_analysis', models.CharField(max_length=255)), + ('add_time', models.DateTimeField()), + ('update_time', models.DateTimeField()), + ('is_display', models.BooleanField()), + ], + ), + migrations.DeleteModel( + name='MyModel', + ), + ] diff --git a/app/migrations/0004_auto_20230531_1032.py b/app/migrations/0004_auto_20230531_1032.py new file mode 100644 index 0000000..86bdddc --- /dev/null +++ b/app/migrations/0004_auto_20230531_1032.py @@ -0,0 +1,23 @@ +# Generated by Django 3.2.19 on 2023-05-31 10:32 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('app', '0003_auto_20230529_1446'), + ] + + operations = [ + migrations.AlterField( + model_name='tp', + name='small_image', + field=models.CharField(max_length=100), + ), + migrations.AlterField( + model_name='tp', + name='video_dir', + field=models.CharField(max_length=100), + ), + ] diff --git a/app/migrations/0005_alter_tp_event_type.py b/app/migrations/0005_alter_tp_event_type.py new file mode 100644 index 0000000..7a8312a --- /dev/null +++ b/app/migrations/0005_alter_tp_event_type.py @@ -0,0 +1,18 @@ +# Generated by Django 3.2.19 on 2023-05-31 14:21 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('app', '0004_auto_20230531_1032'), + ] + + operations = [ + migrations.AlterField( + model_name='tp', + name='event_type', + field=models.CharField(max_length=50), + ), + ] diff --git a/app/migrations/0006_auto_20230531_1757.py b/app/migrations/0006_auto_20230531_1757.py new file mode 100644 index 0000000..6608e93 --- /dev/null +++ b/app/migrations/0006_auto_20230531_1757.py @@ -0,0 +1,28 @@ +# Generated by Django 3.2.19 on 2023-05-31 17:57 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('app', '0005_alter_tp_event_type'), + ] + + operations = [ + migrations.AlterField( + model_name='tp', + name='add_time', + field=models.DateTimeField(auto_now=True), + ), + migrations.AlterField( + model_name='tp', + name='is_display', + field=models.BooleanField(default=True), + ), + migrations.AlterField( + model_name='tp', + name='update_time', + field=models.DateTimeField(auto_now_add=True), + ), + ] diff --git a/app/migrations/0007_auto_20230601_1042.py b/app/migrations/0007_auto_20230601_1042.py new file mode 100644 index 0000000..2e68c39 --- /dev/null +++ b/app/migrations/0007_auto_20230601_1042.py @@ -0,0 +1,23 @@ +# Generated by Django 3.2.19 on 2023-06-01 10:42 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('app', '0006_auto_20230531_1757'), + ] + + operations = [ + migrations.AlterField( + model_name='tp', + name='add_time', + field=models.DateTimeField(auto_now_add=True), + ), + migrations.AlterField( + model_name='tp', + name='update_time', + field=models.DateTimeField(auto_now=True), + ), + ] diff --git a/app/migrations/__pycache__/__init__.cpython-37.pyc b/app/migrations/__pycache__/__init__.cpython-37.pyc deleted file mode 100644 index 5ea9750..0000000 Binary files a/app/migrations/__pycache__/__init__.cpython-37.pyc and /dev/null differ diff --git a/app/models.py b/app/models.py index 71a8362..280166c 100644 --- a/app/models.py +++ b/app/models.py @@ -1,3 +1,36 @@ from django.db import models # Create your models here. +class TP(models.Model): + # uid + uid = models.AutoField(primary_key=True) + # 视频哈希 + video_hash = models.CharField(max_length=50) + # 记录仪时间 + record_time = models.DateTimeField() + # 警号 + police_id = models.CharField(max_length=50) + # 事件类型 + event_type = models.CharField(max_length=50) + # 是否违规 + is_violation = models.BooleanField() + # 缩略图 + small_image = models.CharField(max_length=100) + # 相对时间 + relative_time = models.FloatField() + # 视频路径 + video_dir = models.CharField(max_length=100) + # 车牌号 + car_number = models.CharField(max_length=50) + # 分析结果 + ai_analysis = models.CharField(max_length=255) + # 加入时间 + add_time = models.DateTimeField(auto_now_add=True) + # 更新时间 + update_time = models.DateTimeField(auto_now=True) + # 是否显示 + is_display = models.BooleanField(default=True) + + + + diff --git a/app/pagination.py b/app/pagination.py new file mode 100644 index 0000000..b60b4ab --- /dev/null +++ b/app/pagination.py @@ -0,0 +1,9 @@ +from rest_framework.pagination import PageNumberPagination + + +class MyPageNumberPagination(PageNumberPagination): + page_size = 10 + page_query_param = "page" + page_size_query_param = "page_size" + max_page_size = 100 + diff --git a/app/serializers.py b/app/serializers.py new file mode 100644 index 0000000..e355336 --- /dev/null +++ b/app/serializers.py @@ -0,0 +1,31 @@ +from rest_framework import serializers +from django_filters.rest_framework import FilterSet +import django_filters +from app.models import TP + + +class SerialMyModel(serializers.ModelSerializer): + class Meta: + model = TP + fields = "__all__" + + +class SerialFilter(FilterSet): + """ + 过滤器,支持模糊查询 + record_time,日期时间格式,如 2023-01-01 00:00:00 + police_id,支持模糊匹配 + event_type,支持模糊匹配 + """ + record_time = django_filters.DateTimeFilter(field_name='record_time', lookup_expr='icontains') + police_id = django_filters.CharFilter(field_name='police_id', lookup_expr='icontains') + event_type = django_filters.CharFilter(field_name='event_type', lookup_expr='icontains') + class Meta: + # 指定模型 + models = TP + # 指定需要模糊查询的字段 + fields = ("record_time", "police_id", "event_type",) + + + + diff --git a/TP_Admin/urls.py b/app/urls.py similarity index 69% rename from TP_Admin/urls.py rename to app/urls.py index b28a1c7..2d77315 100644 --- a/TP_Admin/urls.py +++ b/app/urls.py @@ -1,4 +1,4 @@ -"""TP_Admin URL Configuration +"""TP_Api URL Configuration The `urlpatterns` list routes URLs to views. For more information please see: https://docs.djangoproject.com/en/3.2/topics/http/urls/ @@ -13,9 +13,14 @@ 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 +# from django.contrib import admin +from django.urls import path, include +from rest_framework.routers import DefaultRouter +from app import views + +router = DefaultRouter() +router.register('', views.ModelQuery) urlpatterns = [ - path('admin/', admin.site.urls), -] + path('', include(router.urls)), +] \ No newline at end of file diff --git a/app/views.py b/app/views.py index 91ea44a..f59f177 100644 --- a/app/views.py +++ b/app/views.py @@ -1,3 +1,21 @@ from django.shortcuts import render # Create your views here. +from rest_framework import viewsets +from rest_framework.response import Response +from app.models import TP +from app.serializers import SerialMyModel, SerialFilter +from app.pagination import MyPageNumberPagination + + +class ModelQuery(viewsets.ModelViewSet): + # 查询类 + queryset = TP.objects.all().order_by("uid") + # 序列化类 + serializer_class = SerialMyModel + # 分页类 + pagination_class = MyPageNumberPagination + + # 条件筛选 + filterset_class = SerialFilter + diff --git a/db.sqlite3 b/db.sqlite3 new file mode 100644 index 0000000..fa04171 Binary files /dev/null and b/db.sqlite3 differ diff --git a/manage.py b/manage.py index 706baf8..1a237fd 100644 --- a/manage.py +++ b/manage.py @@ -6,7 +6,7 @@ import sys def main(): """Run administrative tasks.""" - os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'TP_Admin.settings') + os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'TP_Api.settings') try: from django.core.management import execute_from_command_line except ImportError as exc: diff --git a/media/images/0000609.jpg b/media/images/0000609.jpg new file mode 100644 index 0000000..6cd41d2 Binary files /dev/null and b/media/images/0000609.jpg differ diff --git a/media/images/0000609_1.jpg b/media/images/0000609_1.jpg new file mode 100644 index 0000000..498ad9a Binary files /dev/null and b/media/images/0000609_1.jpg differ diff --git a/media/images/0000610.jpg b/media/images/0000610.jpg new file mode 100644 index 0000000..6997144 Binary files /dev/null and b/media/images/0000610.jpg differ diff --git a/media/images/0000610_1.jpg b/media/images/0000610_1.jpg new file mode 100644 index 0000000..30c01da Binary files /dev/null and b/media/images/0000610_1.jpg differ diff --git a/media/images/0000610_2.jpg b/media/images/0000610_2.jpg new file mode 100644 index 0000000..034f065 Binary files /dev/null and b/media/images/0000610_2.jpg differ diff --git a/media/images/0000611.jpg b/media/images/0000611.jpg new file mode 100644 index 0000000..dadc2b0 Binary files /dev/null and b/media/images/0000611.jpg differ diff --git a/media/images/0000611_1.jpg b/media/images/0000611_1.jpg new file mode 100644 index 0000000..2b0fc50 Binary files /dev/null and b/media/images/0000611_1.jpg differ diff --git a/media/images/0000611_2.jpg b/media/images/0000611_2.jpg new file mode 100644 index 0000000..8609e44 Binary files /dev/null and b/media/images/0000611_2.jpg differ diff --git a/media/images/0000612.jpg b/media/images/0000612.jpg new file mode 100644 index 0000000..3b99c1d Binary files /dev/null and b/media/images/0000612.jpg differ diff --git a/media/images/0000612_1.jpg b/media/images/0000612_1.jpg new file mode 100644 index 0000000..516f8bd Binary files /dev/null and b/media/images/0000612_1.jpg differ diff --git a/media/images/0000612_2.jpg b/media/images/0000612_2.jpg new file mode 100644 index 0000000..1b52b0b Binary files /dev/null and b/media/images/0000612_2.jpg differ diff --git a/media/images/0000714_1.jpg b/media/images/0000714_1.jpg new file mode 100644 index 0000000..78a9d9f Binary files /dev/null and b/media/images/0000714_1.jpg differ diff --git a/media/images/0000714_2.jpg b/media/images/0000714_2.jpg new file mode 100644 index 0000000..42e9ce1 Binary files /dev/null and b/media/images/0000714_2.jpg differ diff --git a/media/images/0000715.jpg b/media/images/0000715.jpg new file mode 100644 index 0000000..5a16cb0 Binary files /dev/null and b/media/images/0000715.jpg differ diff --git a/media/images/0000715_1.jpg b/media/images/0000715_1.jpg new file mode 100644 index 0000000..48d0d66 Binary files /dev/null and b/media/images/0000715_1.jpg differ diff --git a/media/images/0000715_2.jpg b/media/images/0000715_2.jpg new file mode 100644 index 0000000..24026fb Binary files /dev/null and b/media/images/0000715_2.jpg differ diff --git a/media/images/0000716.jpg b/media/images/0000716.jpg new file mode 100644 index 0000000..8483603 Binary files /dev/null and b/media/images/0000716.jpg differ diff --git a/media/images/0000716_1.jpg b/media/images/0000716_1.jpg new file mode 100644 index 0000000..31ec44f Binary files /dev/null and b/media/images/0000716_1.jpg differ diff --git a/media/images/0000716_2.jpg b/media/images/0000716_2.jpg new file mode 100644 index 0000000..b34623e Binary files /dev/null and b/media/images/0000716_2.jpg differ diff --git a/media/images/0000717.jpg b/media/images/0000717.jpg new file mode 100644 index 0000000..15519b5 Binary files /dev/null and b/media/images/0000717.jpg differ diff --git a/media/images/0000776_2.jpg b/media/images/0000776_2.jpg new file mode 100644 index 0000000..68bcdae Binary files /dev/null and b/media/images/0000776_2.jpg differ diff --git a/media/images/0000779_2.jpg b/media/images/0000779_2.jpg new file mode 100644 index 0000000..d4517fd Binary files /dev/null and b/media/images/0000779_2.jpg differ diff --git a/media/images/0000782_2.jpg b/media/images/0000782_2.jpg new file mode 100644 index 0000000..884d018 Binary files /dev/null and b/media/images/0000782_2.jpg differ diff --git a/media/images/0001151.jpg b/media/images/0001151.jpg new file mode 100644 index 0000000..eaacae1 Binary files /dev/null and b/media/images/0001151.jpg differ diff --git a/media/images/0001151_1.jpg b/media/images/0001151_1.jpg new file mode 100644 index 0000000..13a7b7c Binary files /dev/null and b/media/images/0001151_1.jpg differ diff --git a/media/images/0001151_2.jpg b/media/images/0001151_2.jpg new file mode 100644 index 0000000..34a8116 Binary files /dev/null and b/media/images/0001151_2.jpg differ diff --git a/media/images/0001152.jpg b/media/images/0001152.jpg new file mode 100644 index 0000000..02dc509 Binary files /dev/null and b/media/images/0001152.jpg differ diff --git a/media/images/0001152_1.jpg b/media/images/0001152_1.jpg new file mode 100644 index 0000000..27c31bf Binary files /dev/null and b/media/images/0001152_1.jpg differ diff --git a/media/images/0001152_2.jpg b/media/images/0001152_2.jpg new file mode 100644 index 0000000..6485254 Binary files /dev/null and b/media/images/0001152_2.jpg differ diff --git a/media/images/0001153.jpg b/media/images/0001153.jpg new file mode 100644 index 0000000..fb4ac68 Binary files /dev/null and b/media/images/0001153.jpg differ diff --git a/media/images/0001153_1.jpg b/media/images/0001153_1.jpg new file mode 100644 index 0000000..079fb5e Binary files /dev/null and b/media/images/0001153_1.jpg differ diff --git a/media/images/0001153_2.jpg b/media/images/0001153_2.jpg new file mode 100644 index 0000000..6cd2150 Binary files /dev/null and b/media/images/0001153_2.jpg differ diff --git a/media/images/0001154.jpg b/media/images/0001154.jpg new file mode 100644 index 0000000..d6d0be7 Binary files /dev/null and b/media/images/0001154.jpg differ diff --git a/media/images/0001154_1.jpg b/media/images/0001154_1.jpg new file mode 100644 index 0000000..deb68c7 Binary files /dev/null and b/media/images/0001154_1.jpg differ diff --git a/media/images/0001154_2.jpg b/media/images/0001154_2.jpg new file mode 100644 index 0000000..f7eb7e6 Binary files /dev/null and b/media/images/0001154_2.jpg differ diff --git a/media/images/0001155.jpg b/media/images/0001155.jpg new file mode 100644 index 0000000..1ce4abb Binary files /dev/null and b/media/images/0001155.jpg differ diff --git a/media/images/0001155_1.jpg b/media/images/0001155_1.jpg new file mode 100644 index 0000000..bd1196f Binary files /dev/null and b/media/images/0001155_1.jpg differ diff --git a/media/images/0001155_2.jpg b/media/images/0001155_2.jpg new file mode 100644 index 0000000..3638061 Binary files /dev/null and b/media/images/0001155_2.jpg differ diff --git a/media/images/0001156.jpg b/media/images/0001156.jpg new file mode 100644 index 0000000..30c7748 Binary files /dev/null and b/media/images/0001156.jpg differ diff --git a/media/images/0001156_1.jpg b/media/images/0001156_1.jpg new file mode 100644 index 0000000..b76a278 Binary files /dev/null and b/media/images/0001156_1.jpg differ diff --git a/media/images/0001156_2.jpg b/media/images/0001156_2.jpg new file mode 100644 index 0000000..5099440 Binary files /dev/null and b/media/images/0001156_2.jpg differ diff --git a/media/images/0001157.jpg b/media/images/0001157.jpg new file mode 100644 index 0000000..ce941ce Binary files /dev/null and b/media/images/0001157.jpg differ diff --git a/media/images/0001157_1.jpg b/media/images/0001157_1.jpg new file mode 100644 index 0000000..5f23b4e Binary files /dev/null and b/media/images/0001157_1.jpg differ diff --git a/media/images/0003091.jpg b/media/images/0003091.jpg new file mode 100644 index 0000000..5d91d08 Binary files /dev/null and b/media/images/0003091.jpg differ diff --git a/media/images/0003091_1.jpg b/media/images/0003091_1.jpg new file mode 100644 index 0000000..5d5b55d Binary files /dev/null and b/media/images/0003091_1.jpg differ diff --git a/media/images/0003092.jpg b/media/images/0003092.jpg new file mode 100644 index 0000000..dbd6cd7 Binary files /dev/null and b/media/images/0003092.jpg differ diff --git a/media/images/0003092_1.jpg b/media/images/0003092_1.jpg new file mode 100644 index 0000000..1e337d5 Binary files /dev/null and b/media/images/0003092_1.jpg differ diff --git a/media/images/0003093.jpg b/media/images/0003093.jpg new file mode 100644 index 0000000..0b4cf6b Binary files /dev/null and b/media/images/0003093.jpg differ diff --git a/media/images/0003095.jpg b/media/images/0003095.jpg new file mode 100644 index 0000000..a790d51 Binary files /dev/null and b/media/images/0003095.jpg differ diff --git a/media/images/0003095_1.jpg b/media/images/0003095_1.jpg new file mode 100644 index 0000000..22a6f1e Binary files /dev/null and b/media/images/0003095_1.jpg differ diff --git a/media/images/0003096.jpg b/media/images/0003096.jpg new file mode 100644 index 0000000..b20a98f Binary files /dev/null and b/media/images/0003096.jpg differ diff --git a/media/images/0003096_1.jpg b/media/images/0003096_1.jpg new file mode 100644 index 0000000..bc3d54a Binary files /dev/null and b/media/images/0003096_1.jpg differ diff --git a/media/images/0003097.jpg b/media/images/0003097.jpg new file mode 100644 index 0000000..e8d7f9a Binary files /dev/null and b/media/images/0003097.jpg differ diff --git a/media/images/IMG_2630.JPG b/media/images/IMG_2630.JPG new file mode 100644 index 0000000..bed5c71 Binary files /dev/null and b/media/images/IMG_2630.JPG differ diff --git a/media/images/IMG_2631.JPG b/media/images/IMG_2631.JPG new file mode 100644 index 0000000..3e52e6c Binary files /dev/null and b/media/images/IMG_2631.JPG differ diff --git a/media/images/IMG_2632.JPG b/media/images/IMG_2632.JPG new file mode 100644 index 0000000..416d4ac Binary files /dev/null and b/media/images/IMG_2632.JPG differ diff --git a/media/images/IMG_2633.JPG b/media/images/IMG_2633.JPG new file mode 100644 index 0000000..7deeeb1 Binary files /dev/null and b/media/images/IMG_2633.JPG differ diff --git a/media/images/IMG_2634.JPG b/media/images/IMG_2634.JPG new file mode 100644 index 0000000..e6d53eb Binary files /dev/null and b/media/images/IMG_2634.JPG differ diff --git a/media/video/B1.MP4 b/media/video/B1.MP4 new file mode 100644 index 0000000..b7d5549 Binary files /dev/null and b/media/video/B1.MP4 differ diff --git a/media/video/G1TPelect.avi b/media/video/G1TPelect.avi new file mode 100644 index 0000000..a370309 Binary files /dev/null and b/media/video/G1TPelect.avi differ