Skip to content

Commit dbd1cf5

Browse files
authored
Remove python-dotenv dep. Bump django. Add django example. (#63)
1 parent c529060 commit dbd1cf5

27 files changed

Lines changed: 1166 additions & 539 deletions

File tree

docs/build.py

Lines changed: 6 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,12 @@ def read_cls_docstring(cls):
3939

4040
def get_versions():
4141
return [
42+
{
43+
"version": "0.2.12",
44+
"changes": [
45+
"Remove python-dotenv dep. Bump django. Add django example.",
46+
],
47+
},
4248
{
4349
"version": "0.2.11",
4450
"changes": [
@@ -111,72 +117,6 @@ def get_versions():
111117
"Update packages. Use vite instead obsolete react-scripts.",
112118
],
113119
},
114-
{
115-
"version": "0.1.41",
116-
"changes": [
117-
"Fixed bug with datetime. Added verbose name logic for models and inlines. Updated frontend libraries.",
118-
],
119-
},
120-
{
121-
"version": "0.1.40",
122-
"changes": [
123-
"Added RUFF linter. Cleaned up code. Removed pydantic dependency.",
124-
],
125-
},
126-
{
127-
"version": "0.1.39",
128-
"changes": [
129-
"Bug fixes.",
130-
],
131-
},
132-
{
133-
"version": "0.1.38",
134-
"changes": [
135-
"Bug fixes.",
136-
],
137-
},
138-
{
139-
"version": "0.1.37",
140-
"changes": [
141-
"Bug fixes.",
142-
],
143-
},
144-
{
145-
"version": "0.1.36",
146-
"changes": [
147-
"Added autogeneration of documentation and examples.",
148-
],
149-
},
150-
{
151-
"version": "0.1.35",
152-
"changes": [
153-
"Added DashboardWidgetAdmin class and charts for dashboard.",
154-
],
155-
},
156-
{
157-
"version": "0.1.34",
158-
"changes": [
159-
"Added SlugInput, EmailInput, PhoneInput, UrlInput, JsonTextArea widget types.",
160-
],
161-
},
162-
{
163-
"version": "0.1.33",
164-
"changes": [
165-
"Added list_display_widths parameter.",
166-
],
167-
},
168-
{
169-
"version": "0.1.32",
170-
"changes": [
171-
"Added Upload widget type.",
172-
],
173-
},
174-
{
175-
"version": "0.1.31",
176-
"changes": [
177-
"Added PasswordInput widget type.",
178-
],
179-
},
180120
]
181121

182122

docs/index.html

Lines changed: 2 additions & 2 deletions
Large diffs are not rendered by default.

examples/django_djangoorm/Makefile

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
all: install run
2+
3+
.PHONY: fastapi
4+
run:
5+
poetry run python manage.py migrate
6+
poetry run python manage.py runserver
7+
8+
.PHONY: install
9+
install:
10+
poetry install
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
## Django + Django ORM Example
2+
3+
- Uses in-memory SQLite 3 instance
4+
- Creates "admin/admin" superuser
5+
- Setup env variables in __init__.py
6+
7+
```bash
8+
make install # Creates virtualenv with Poetry
9+
make run # Runs fastapi dev
10+
```
11+
12+
So open `http://127.0.0.1:8000/admin/` and have a fun!
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import os
2+
import sys
3+
from pathlib import Path
4+
5+
os.environ["ADMIN_USER_MODEL"] = "User"
6+
os.environ["ADMIN_USER_MODEL_USERNAME_FIELD"] = "username"
7+
os.environ["ADMIN_SECRET_KEY"] = "secret"
8+
9+
sys.path.append(str(Path(__file__).resolve().parent))

examples/django_djangoorm/dev/__init__.py

Whitespace-only changes.
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
"""
2+
ASGI config for dev project.
3+
4+
It exposes the ASGI callable as a module-level variable named ``application``.
5+
6+
For more information on this file, see
7+
https://docs.djangoproject.com/en/4.1/howto/deployment/asgi/
8+
"""
9+
10+
import os
11+
12+
from django.core.asgi import get_asgi_application
13+
14+
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "dev.settings")
15+
application = get_asgi_application()
Lines changed: 139 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,139 @@
1+
"""
2+
Django settings for dev project.
3+
4+
Generated by 'django-admin startproject' using Django 4.1.7.
5+
6+
For more information on this file, see
7+
https://docs.djangoproject.com/en/4.1/topics/settings/
8+
9+
For the full list of settings and their values, see
10+
https://docs.djangoproject.com/en/4.1/ref/settings/
11+
"""
12+
13+
from pathlib import Path
14+
15+
# Build paths inside the project like this: BASE_DIR / 'subdir'.
16+
BASE_DIR = Path(__file__).resolve().parent.parent
17+
18+
19+
# Quick-start development settings - unsuitable for production
20+
# See https://docs.djangoproject.com/en/4.1/howto/deployment/checklist/
21+
22+
# SECURITY WARNING: keep the secret key used in production secret!
23+
SECRET_KEY = "test"
24+
25+
# SECURITY WARNING: don't run with debug turned on in production!
26+
DEBUG = False
27+
28+
ALLOWED_HOSTS = ["*"]
29+
30+
31+
# Application definition
32+
33+
INSTALLED_APPS = [
34+
"django.contrib.admin",
35+
"django.contrib.auth",
36+
"django.contrib.contenttypes",
37+
"django.contrib.sessions",
38+
"django.contrib.messages",
39+
"django.contrib.staticfiles",
40+
"orm",
41+
]
42+
43+
MIDDLEWARE = [
44+
"django.middleware.security.SecurityMiddleware",
45+
"django.contrib.sessions.middleware.SessionMiddleware",
46+
"django.middleware.common.CommonMiddleware",
47+
"django.middleware.csrf.CsrfViewMiddleware",
48+
"django.contrib.auth.middleware.AuthenticationMiddleware",
49+
"django.contrib.messages.middleware.MessageMiddleware",
50+
"django.middleware.clickjacking.XFrameOptionsMiddleware",
51+
]
52+
53+
ROOT_URLCONF = "dev.urls"
54+
55+
TEMPLATES = [
56+
{
57+
"BACKEND": "django.template.backends.django.DjangoTemplates",
58+
"DIRS": [],
59+
"APP_DIRS": True,
60+
"OPTIONS": {
61+
"context_processors": [
62+
"django.template.context_processors.debug",
63+
"django.template.context_processors.request",
64+
"django.contrib.auth.context_processors.auth",
65+
"django.contrib.messages.context_processors.messages",
66+
],
67+
},
68+
},
69+
]
70+
71+
WSGI_APPLICATION = "dev.wsgi.application"
72+
73+
74+
# Database
75+
# https://docs.djangoproject.com/en/4.1/ref/settings/#databases
76+
77+
DATABASES = {
78+
"default": {
79+
"ENGINE": "django.db.backends.sqlite3",
80+
"NAME": ":sharedmemory:",
81+
}
82+
}
83+
84+
85+
# Password validation
86+
# https://docs.djangoproject.com/en/4.1/ref/settings/#auth-password-validators
87+
88+
AUTH_PASSWORD_VALIDATORS = [
89+
{
90+
"NAME": "django.contrib.auth.password_validation.UserAttributeSimilarityValidator",
91+
},
92+
{
93+
"NAME": "django.contrib.auth.password_validation.MinimumLengthValidator",
94+
},
95+
{
96+
"NAME": "django.contrib.auth.password_validation.CommonPasswordValidator",
97+
},
98+
{
99+
"NAME": "django.contrib.auth.password_validation.NumericPasswordValidator",
100+
},
101+
]
102+
103+
104+
# Internationalization
105+
# https://docs.djangoproject.com/en/4.1/topics/i18n/
106+
107+
LANGUAGE_CODE = "en-us"
108+
109+
TIME_ZONE = "UTC"
110+
111+
USE_I18N = True
112+
113+
USE_TZ = True
114+
115+
116+
# Static files (CSS, JavaScript, Images)
117+
# https://docs.djangoproject.com/en/4.1/howto/static-files/
118+
119+
STATIC_URL = "static/"
120+
121+
# Default primary key field type
122+
# https://docs.djangoproject.com/en/4.1/ref/settings/#default-auto-field
123+
124+
DEFAULT_AUTO_FIELD = "django.db.models.BigAutoField"
125+
126+
# Logging
127+
LOGGING = {
128+
"version": 1,
129+
"disable_existing_loggers": True,
130+
"handlers": {
131+
"console": {
132+
"class": "logging.StreamHandler",
133+
},
134+
},
135+
"root": {
136+
"handlers": ["console"],
137+
"level": "ERROR",
138+
},
139+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
from django.urls import path
2+
3+
from fastadmin import get_django_admin_urls as get_admin_urls
4+
from fastadmin.settings import settings
5+
6+
urlpatterns = [
7+
path(f"{settings.ADMIN_PREFIX}/", get_admin_urls()),
8+
]
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
"""
2+
WSGI config for dev project.
3+
4+
It exposes the WSGI callable as a module-level variable named ``application``.
5+
6+
For more information on this file, see
7+
https://docs.djangoproject.com/en/4.1/howto/deployment/wsgi/
8+
"""
9+
10+
import os
11+
12+
from django.core.wsgi import get_wsgi_application
13+
14+
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "dev.settings")
15+
16+
application = get_wsgi_application()

0 commit comments

Comments
 (0)