diff --git a/README.md b/README.md index 5aee7c4..bd1f3ad 100644 --- a/README.md +++ b/README.md @@ -18,10 +18,16 @@ Default local DB is SQLite via `config/local_settings.py`. For PostgreSQL, overr ## API -- Public & staff CRUD: `/api/articles/`, `/api/organizes/`, `/api/subjects/`, `/api/organize-categories/`, `/api/magazine-categories/`, `/api/work-groups/`, `/api/work-group-terms/`, `/api/columns/`, … -- Auth: `POST /api/auth/login/`, `GET /api/auth/me/` -- Django admin: `/django-admin/` -- Search: `GET /api/search/?q=` +路由按 app 划分前缀(网关再统一挂 `/api`): + +| 前缀 | App | 示例 | +|------|-----|------| +| `/api/auth/` | `accounts` | `POST /api/auth/login/`、`GET /api/auth/me/` | +| `/api/common/` | `common` | `POST /api/common/uploads/` | +| `/api/content/` | `content` | `/api/content/articles/`、`/api/content/columns/`、… | +| `/api/cms/` | `cms` | `/api/cms/news/`、`GET /api/cms/search/?q=` | + +Django admin: `/django-admin/` Staff write operations require `Authorization: Token ` and `is_staff=True`. diff --git a/apps/__init__.py b/accounts/__init__.py similarity index 100% rename from apps/__init__.py rename to accounts/__init__.py diff --git a/apps/accounts/admin.py b/accounts/admin.py similarity index 100% rename from apps/accounts/admin.py rename to accounts/admin.py diff --git a/apps/accounts/apps.py b/accounts/apps.py similarity index 86% rename from apps/accounts/apps.py rename to accounts/apps.py index e6b12d5..4667faa 100644 --- a/apps/accounts/apps.py +++ b/accounts/apps.py @@ -3,6 +3,6 @@ from django.apps import AppConfig class AccountsConfig(AppConfig): default_auto_field = "django.db.models.BigAutoField" - name = "apps.accounts" + name = "accounts" label = "accounts" verbose_name = "账号" diff --git a/apps/accounts/__init__.py b/accounts/management/__init__.py similarity index 100% rename from apps/accounts/__init__.py rename to accounts/management/__init__.py diff --git a/apps/accounts/management/__init__.py b/accounts/management/commands/__init__.py similarity index 100% rename from apps/accounts/management/__init__.py rename to accounts/management/commands/__init__.py diff --git a/apps/accounts/management/commands/seed_demo.py b/accounts/management/commands/seed_demo.py similarity index 99% rename from apps/accounts/management/commands/seed_demo.py rename to accounts/management/commands/seed_demo.py index d538096..4db0fae 100644 --- a/apps/accounts/management/commands/seed_demo.py +++ b/accounts/management/commands/seed_demo.py @@ -2,7 +2,7 @@ from decimal import Decimal from django.core.management.base import BaseCommand -from apps.cms.models import ( +from cms.models import ( AboutInfo, ContactUs, CopyrightInfo, @@ -12,8 +12,8 @@ from apps.cms.models import ( News, Publication, ) -from apps.accounts.models import Member -from apps.content.models import ( +from accounts.models import Member +from content.models import ( Article, ArticleComment, Column, @@ -478,7 +478,7 @@ class Command(BaseCommand): return created, updated def _ensure_demo_comments(self): - from apps.accounts.serializers import MemberSerializer + from accounts.serializers import MemberSerializer # 国际格式;同时兼容旧的 11 位国内号演示数据 member = ( diff --git a/apps/accounts/management/commands/sync_nav_columns.py b/accounts/management/commands/sync_nav_columns.py similarity index 98% rename from apps/accounts/management/commands/sync_nav_columns.py rename to accounts/management/commands/sync_nav_columns.py index 56ea5dd..42590e8 100644 --- a/apps/accounts/management/commands/sync_nav_columns.py +++ b/accounts/management/commands/sync_nav_columns.py @@ -2,7 +2,7 @@ from django.core.management.base import BaseCommand -from apps.content.models import Column, NavPosition +from content.models import Column, NavPosition # 与 ui/src/config/nav.js 对齐 diff --git a/apps/accounts/migrations/0001_initial.py b/accounts/migrations/0001_initial.py similarity index 100% rename from apps/accounts/migrations/0001_initial.py rename to accounts/migrations/0001_initial.py diff --git a/apps/accounts/migrations/__init__.py b/accounts/migrations/__init__.py similarity index 100% rename from apps/accounts/migrations/__init__.py rename to accounts/migrations/__init__.py diff --git a/apps/accounts/models.py b/accounts/models.py similarity index 96% rename from apps/accounts/models.py rename to accounts/models.py index 4bf2fea..106ae44 100644 --- a/apps/accounts/models.py +++ b/accounts/models.py @@ -1,7 +1,7 @@ from django.conf import settings from django.db import models -from apps.common.models import SoftDeleteModel +from common.models import SoftDeleteModel class Member(SoftDeleteModel): diff --git a/apps/accounts/phone.py b/accounts/phone.py similarity index 100% rename from apps/accounts/phone.py rename to accounts/phone.py diff --git a/apps/accounts/serializers.py b/accounts/serializers.py similarity index 100% rename from apps/accounts/serializers.py rename to accounts/serializers.py diff --git a/apps/accounts/urls.py b/accounts/urls.py similarity index 100% rename from apps/accounts/urls.py rename to accounts/urls.py diff --git a/apps/accounts/views.py b/accounts/views.py similarity index 100% rename from apps/accounts/views.py rename to accounts/views.py diff --git a/apps/content/migrations/__init__.py b/apps/content/migrations/__init__.py deleted file mode 100644 index e69de29..0000000 diff --git a/apps/accounts/management/commands/__init__.py b/cms/__init__.py similarity index 100% rename from apps/accounts/management/commands/__init__.py rename to cms/__init__.py diff --git a/apps/cms/admin.py b/cms/admin.py similarity index 100% rename from apps/cms/admin.py rename to cms/admin.py diff --git a/apps/cms/apps.py b/cms/apps.py similarity index 88% rename from apps/cms/apps.py rename to cms/apps.py index 6cf3480..cb20f45 100644 --- a/apps/cms/apps.py +++ b/cms/apps.py @@ -3,6 +3,6 @@ from django.apps import AppConfig class CmsConfig(AppConfig): default_auto_field = "django.db.models.BigAutoField" - name = "apps.cms" + name = "cms" label = "cms" verbose_name = "站点内容" diff --git a/apps/cms/migrations/0001_initial.py b/cms/migrations/0001_initial.py similarity index 100% rename from apps/cms/migrations/0001_initial.py rename to cms/migrations/0001_initial.py diff --git a/apps/cms/__init__.py b/cms/migrations/__init__.py similarity index 100% rename from apps/cms/__init__.py rename to cms/migrations/__init__.py diff --git a/apps/cms/models.py b/cms/models.py similarity index 99% rename from apps/cms/models.py rename to cms/models.py index 0f86613..111d000 100644 --- a/apps/cms/models.py +++ b/cms/models.py @@ -1,6 +1,6 @@ from django.db import models -from apps.common.models import SoftDeleteModel +from common.models import SoftDeleteModel class News(SoftDeleteModel): diff --git a/apps/cms/serializers.py b/cms/serializers.py similarity index 100% rename from apps/cms/serializers.py rename to cms/serializers.py diff --git a/apps/cms/urls.py b/cms/urls.py similarity index 100% rename from apps/cms/urls.py rename to cms/urls.py diff --git a/apps/cms/views.py b/cms/views.py similarity index 97% rename from apps/cms/views.py rename to cms/views.py index 107bee9..4cb1d88 100644 --- a/apps/cms/views.py +++ b/cms/views.py @@ -9,13 +9,13 @@ from rest_framework.decorators import action from rest_framework.parsers import FormParser, MultiPartParser from rest_framework.response import Response -from apps.content.models import Article, Organize, Professor -from apps.content.serializers import ( +from content.models import Article, Organize, Professor +from content.serializers import ( ArticleListSerializer, OrganizeListSerializer, ProfessorSerializer, ) -from apps.content.views import IsAdminOrReadOnly, PublicMixin +from content.views import IsAdminOrReadOnly, PublicMixin ALLOWED_IMAGE_EXT = {".jpg", ".jpeg", ".png", ".gif", ".webp", ".svg"} MAX_UPLOAD_BYTES = 8 * 1024 * 1024 diff --git a/apps/cms/migrations/__init__.py b/common/__init__.py similarity index 100% rename from apps/cms/migrations/__init__.py rename to common/__init__.py diff --git a/apps/common/apps.py b/common/apps.py similarity index 87% rename from apps/common/apps.py rename to common/apps.py index 18d1fa7..f82052b 100644 --- a/apps/common/apps.py +++ b/common/apps.py @@ -3,6 +3,6 @@ from django.apps import AppConfig class CommonConfig(AppConfig): default_auto_field = "django.db.models.BigAutoField" - name = "apps.common" + name = "common" label = "common" verbose_name = "公共" diff --git a/apps/common/models.py b/common/models.py similarity index 100% rename from apps/common/models.py rename to common/models.py diff --git a/apps/common/upload.py b/common/upload.py similarity index 96% rename from apps/common/upload.py rename to common/upload.py index 7d007b1..474b013 100644 --- a/apps/common/upload.py +++ b/common/upload.py @@ -32,7 +32,7 @@ CATEGORY_RE = re.compile(r"^[a-zA-Z0-9_-]{1,32}$") class MediaUploadView(APIView): - """POST /api/uploads/ 表单字段: file, category(可选), kind=image|file(可选)""" + """POST /uploads/ 表单字段: file, category(可选), kind=image|file(可选)""" permission_classes = [permissions.IsAdminUser] parser_classes = [MultiPartParser, FormParser] diff --git a/apps/common/urls.py b/common/urls.py similarity index 100% rename from apps/common/urls.py rename to common/urls.py diff --git a/config/settings.py b/config/settings.py index 2075483..4f48dd8 100644 --- a/config/settings.py +++ b/config/settings.py @@ -45,10 +45,10 @@ INSTALLED_APPS = [ "django_extensions", "simple_history", "corsheaders", - "apps.common", - "apps.content", - "apps.cms", - "apps.accounts", + "common", + "content", + "cms", + "accounts", ] MIDDLEWARE = [ diff --git a/config/urls.py b/config/urls.py index 0ca063b..9dfe6b6 100644 --- a/config/urls.py +++ b/config/urls.py @@ -5,10 +5,10 @@ from django.urls import include, path urlpatterns = [ path("django-admin/", admin.site.urls), - path("api/auth/", include("apps.accounts.urls")), - path("api/", include("apps.common.urls")), - path("api/", include("apps.content.urls")), - path("api/", include("apps.cms.urls")), + path("auth/", include("accounts.urls")), + path("common/", include("common.urls")), + path("content/", include("content.urls")), + path("cms/", include("cms.urls")), ] if settings.DEBUG: diff --git a/apps/common/__init__.py b/content/__init__.py similarity index 100% rename from apps/common/__init__.py rename to content/__init__.py diff --git a/apps/content/admin.py b/content/admin.py similarity index 100% rename from apps/content/admin.py rename to content/admin.py diff --git a/apps/content/apps.py b/content/apps.py similarity index 87% rename from apps/content/apps.py rename to content/apps.py index 989f7b4..040bd46 100644 --- a/apps/content/apps.py +++ b/content/apps.py @@ -3,6 +3,6 @@ from django.apps import AppConfig class ContentConfig(AppConfig): default_auto_field = "django.db.models.BigAutoField" - name = "apps.content" + name = "content" label = "content" verbose_name = "内容" diff --git a/apps/content/filters.py b/content/filters.py similarity index 100% rename from apps/content/filters.py rename to content/filters.py diff --git a/apps/content/migrations/0001_initial.py b/content/migrations/0001_initial.py similarity index 100% rename from apps/content/migrations/0001_initial.py rename to content/migrations/0001_initial.py diff --git a/apps/content/migrations/0002_seed_article_types.py b/content/migrations/0002_seed_article_types.py similarity index 100% rename from apps/content/migrations/0002_seed_article_types.py rename to content/migrations/0002_seed_article_types.py diff --git a/apps/content/__init__.py b/content/migrations/__init__.py similarity index 100% rename from apps/content/__init__.py rename to content/migrations/__init__.py diff --git a/apps/content/models.py b/content/models.py similarity index 99% rename from apps/content/models.py rename to content/models.py index d29f4d1..6e30cf2 100644 --- a/apps/content/models.py +++ b/content/models.py @@ -1,6 +1,6 @@ from django.db import models -from apps.common.models import SoftDeleteModel, TimeStampedModel +from common.models import SoftDeleteModel, TimeStampedModel class NavPosition(models.IntegerChoices): diff --git a/apps/content/serializers.py b/content/serializers.py similarity index 100% rename from apps/content/serializers.py rename to content/serializers.py diff --git a/apps/content/urls.py b/content/urls.py similarity index 100% rename from apps/content/urls.py rename to content/urls.py diff --git a/apps/content/views.py b/content/views.py similarity index 100% rename from apps/content/views.py rename to content/views.py