@cubocicloide/stack-react-django 3.2.0 → 3.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cubocicloide/stack-react-django",
3
- "version": "3.2.0",
3
+ "version": "3.3.0",
4
4
  "description": "React (Vite) + Django REST Framework stack plugin for the dude CLI.",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
@@ -76,7 +76,7 @@ A **new app** touches all of these; extending an existing app touches a subset.
76
76
  | `apps/<app>/views.py` | BE003, BE013 | ViewSet/APIView with explicit `permission_classes` and `serializer_class` (or `@extend_schema`) |
77
77
  | `apps/<app>/urls.py` | BE008 | `app_name = "<app>"` + DRF router |
78
78
  | `config/urls.py` | BE008 | `path("api/", include("apps.<app>.urls"))` |
79
- | `apps/<app>/admin.py` | — | register the model |
79
+ | `apps/<app>/admin.py` | — | register the model — subclass `unfold.admin.ModelAdmin`, never `admin.ModelAdmin` (Unfold theme) |
80
80
  | `apps/<app>/tests/test_*.py` | BE014 | model + view tests (pytest-django, `APIClient`) |
81
81
 
82
82
  Skip rows that don't apply. Present the list, then wait for an OK.
@@ -338,6 +338,11 @@ dude db migrate
338
338
  fields (BE010), explicit `related_name` (BE011); every change ships a
339
339
  committed migration (BE006).
340
340
  - `urls.py` — `app_name` + DRF router, mounted under `/api/` in `config/urls.py` (BE008).
341
+ - `admin.py` — subclass **`unfold.admin.ModelAdmin`**, never `django.contrib.admin.ModelAdmin`.
342
+ The admin is themed by [django-unfold](https://unfoldadmin.com) (`UNFOLD` in
343
+ `config/settings/base.py`); Django's own `ModelAdmin` still works but renders
344
+ unstyled inside the themed layout. For the auth user model, keep Unfold's form
345
+ overrides — see `apps/users/admin.py`.
341
346
  - `tests/` — required for every app (BE014). No raw SQL (BE004), no `print()` (BE012).
342
347
 
343
348
  ### Frontend (`frontend/src/`)
@@ -65,7 +65,7 @@ Once the containers are up, open the URLs below.
65
65
  | **API reference** | http://localhost:8000/api/docs/ | Interactive reference (Scalar) — narrative in `backend/config/api_docs.py` |
66
66
  | **OpenAPI schema** | http://localhost:8000/api/schema/ | Raw schema (YAML, drf-spectacular) |
67
67
  | **Health** | http://localhost:8000/api/health/ | JSON health check |
68
- | **Django admin** | http://localhost:8000/admin/ | Create an account with `dude db superuser` |
68
+ | **Django admin** | http://localhost:8000/admin/ | Themed by [Unfold](https://unfoldadmin.com); create an account with `dude db superuser` |
69
69
  {{#if withS3}}
70
70
  | **MinIO console** | http://localhost:9001 | Object-storage UI (minioadmin/minioadmin) |
71
71
  {{/if}}
@@ -65,6 +65,20 @@ Create an admin account for <http://localhost:8000/admin/>:
65
65
  ```bash
66
66
  dude db superuser
67
67
  ```
68
+
69
+ The admin is themed by [django-unfold](https://unfoldadmin.com) (configured via
70
+ `UNFOLD` in `config/settings/base.py`). When you register a new model, subclass
71
+ **Unfold's** `ModelAdmin`, not Django's — Django's renders unstyled inside the
72
+ themed layout:
73
+
74
+ ```python
75
+ from django.contrib import admin
76
+ from unfold.admin import ModelAdmin
77
+
78
+ @admin.register(MyModel)
79
+ class MyModelAdmin(ModelAdmin):
80
+ ...
81
+ ```
68
82
  {{#if withCelery}}
69
83
 
70
84
  Celery worker{{#if withCeleryBeat}}, beat scheduler{{/if}} and Flower monitor are started automatically by docker compose.
@@ -1,6 +1,23 @@
1
1
  from django.contrib import admin
2
- from django.contrib.auth.admin import UserAdmin
2
+ from django.contrib.auth.admin import UserAdmin as BaseUserAdmin
3
+ from unfold.admin import ModelAdmin
4
+ from unfold.forms import AdminPasswordChangeForm, UserChangeForm, UserCreationForm
3
5
 
4
6
  from apps.users.models import User
5
7
 
6
- admin.site.register(User, UserAdmin)
8
+
9
+ @admin.register(User)
10
+ class UserAdmin(BaseUserAdmin, ModelAdmin):
11
+ """Django's user admin, restyled by Unfold.
12
+
13
+ ``BaseUserAdmin`` comes first so its fieldsets and password handling win;
14
+ ``ModelAdmin`` (Unfold's) supplies the templates.
15
+
16
+ The three form overrides are not optional: Django's auth forms ship their own
17
+ widgets, so without Unfold's replacements the add / change / set-password
18
+ screens render unstyled inside the themed layout.
19
+ """
20
+
21
+ form = UserChangeForm
22
+ add_form = UserCreationForm
23
+ change_password_form = AdminPasswordChangeForm
@@ -22,6 +22,23 @@ BASE_DIR = Path(__file__).resolve().parent.parent.parent
22
22
 
23
23
  # ── Application definition ────────────────────────────────────────────────────
24
24
 
25
+ # django-unfold — the admin theme. Every entry MUST precede
26
+ # "django.contrib.admin": Unfold works by overriding the admin's templates, and
27
+ # Django resolves templates in INSTALLED_APPS order, so listing it later silently
28
+ # gives you the stock admin back.
29
+ #
30
+ # The three contrib modules below pull in no extra packages. The remaining ones
31
+ # each need their own dependency, so add both together if you want them:
32
+ # unfold.contrib.import_export (django-import-export),
33
+ # unfold.contrib.guardian (django-guardian),
34
+ # unfold.contrib.simple_history (django-simple-history).
35
+ ADMIN_APPS = [
36
+ "unfold",
37
+ "unfold.contrib.filters",
38
+ "unfold.contrib.forms",
39
+ "unfold.contrib.inlines",
40
+ ]
41
+
25
42
  DJANGO_APPS = [
26
43
  "django.contrib.admin",
27
44
  "django.contrib.auth",
@@ -48,7 +65,7 @@ LOCAL_APPS = [
48
65
  {{/if}}
49
66
  ]
50
67
 
51
- INSTALLED_APPS = DJANGO_APPS + THIRD_PARTY_APPS + LOCAL_APPS
68
+ INSTALLED_APPS = ADMIN_APPS + DJANGO_APPS + THIRD_PARTY_APPS + LOCAL_APPS
52
69
 
53
70
  MIDDLEWARE = [
54
71
  "django.middleware.security.SecurityMiddleware",
@@ -148,6 +165,30 @@ AWS_DEFAULT_ACL = None
148
165
  AWS_QUERYSTRING_AUTH = True # serve files via presigned URLs
149
166
  {{/if}}
150
167
 
168
+ # ── Admin theme (django-unfold) ───────────────────────────────────────────────
169
+ # Needs no URL wiring — Unfold themes the stock admin site at /admin/ by
170
+ # overriding its templates. ModelAdmin classes must subclass
171
+ # `unfold.admin.ModelAdmin` to pick up the styling (see apps/users/admin.py).
172
+ #
173
+ # Full option list: https://unfoldadmin.com/docs/configuration/settings/
174
+ UNFOLD = {
175
+ "SITE_TITLE": env("APP_TITLE", default="{{projectName}}") + " admin",
176
+ "SITE_HEADER": env("APP_TITLE", default="{{projectName}}"),
177
+ # Link the header back to the frontend.
178
+ "SITE_URL": "/",
179
+ "SHOW_HISTORY": True,
180
+ "SHOW_VIEW_ON_SITE": True,
181
+ "SIDEBAR": {
182
+ "show_search": True,
183
+ # No "navigation" key → Unfold renders the standard app/model list.
184
+ # Add one to hand-order the sidebar as the project grows.
185
+ },
186
+ # To match the frontend's accent, add a "COLORS" ramp here — Unfold wants
187
+ # space-separated RGB channels per Tailwind shade, e.g.
188
+ # "COLORS": {"primary": {"500": "22 119 255", …}}. Omitted so the scaffold
189
+ # ships Unfold's own tested palette rather than a half-filled one.
190
+ }
191
+
151
192
  # ── Django REST Framework ─────────────────────────────────────────────────────
152
193
 
153
194
  REST_FRAMEWORK = {
@@ -9,6 +9,7 @@ dependencies = [
9
9
  "drf-spectacular>=0.28.0",
10
10
  "django-environ>=0.11.0",
11
11
  "django-cors-headers>=4.6.0",
12
+ "django-unfold>=0.102.0",
12
13
  "whitenoise>=6.8.0",
13
14
  "gunicorn>=23.0.0",
14
15
  {{#if withPostgres}}
@@ -57,7 +57,7 @@ Once the stack is up, open these URLs:
57
57
  | **API reference** | http://localhost:8000/api/docs/ | Interactive reference (Scalar) |
58
58
  | **OpenAPI schema** | http://localhost:8000/api/schema/ | Raw schema (YAML, drf-spectacular) |
59
59
  | **Health** | http://localhost:8000/api/health/ | JSON health check |
60
- | **Django admin** | http://localhost:8000/admin/ | Create an account with `dude db superuser` |
60
+ | **Django admin** | http://localhost:8000/admin/ | Themed by [Unfold](https://unfoldadmin.com); create an account with `dude db superuser` |
61
61
  {{#if withS3}}| **MinIO console** | http://localhost:9001 | Object-storage UI (minioadmin/minioadmin) |
62
62
  {{/if}}
63
63
  {{#if withCelery}}| **Flower** | http://localhost:5555 | Celery task monitor |
@@ -58,7 +58,7 @@ dude docs # → http://localhost:8001
58
58
  | API reference (Scalar) | <http://localhost:8000/api/docs/> |
59
59
  | OpenAPI schema | <http://localhost:8000/api/schema/> |
60
60
  | API health | <http://localhost:8000/api/health/> |
61
- | Django admin | <http://localhost:8000/admin/> |
61
+ | Django admin (Unfold theme) | <http://localhost:8000/admin/> |
62
62
  {{#if withS3}}
63
63
  | MinIO console | <http://localhost:9001> |
64
64
  {{/if}}
@@ -1,9 +1,12 @@
1
1
  from django.contrib import admin
2
+ from unfold.admin import ModelAdmin
2
3
 
3
4
  from apps.files.models import FileUpload
4
5
 
5
6
 
6
7
  @admin.register(FileUpload)
7
- class FileUploadAdmin(admin.ModelAdmin):
8
+ class FileUploadAdmin(ModelAdmin):
9
+ # Unfold's ModelAdmin, not django.contrib.admin's — that is what applies the
10
+ # admin theme (see UNFOLD in config/settings/base.py).
8
11
  list_display = ("id", "original_name", "content_type", "size", "created_at")
9
12
  readonly_fields = ("created_at",)