Skip to content

Commit 8f4a9d1

Browse files
committed
Add backend-django
1 parent 047e4ef commit 8f4a9d1

51 files changed

Lines changed: 1010 additions & 0 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

backend-django/.gitignore

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
.venv/
2+
3+
__pycache__/
4+
*.py[cod]
5+
*$py.class
6+
7+
db.sqlite3
8+
9+
.pytest_cache/
10+
.coverage
11+
htmlcov/
12+
13+
.vscode/
14+
.idea/
15+
16+
*.log
17+
18+
staticfiles/
19+
mediafiles/
20+
21+
.env
22+
.env.*
23+
24+
dist/
25+
build/
26+
27+
.DS_Store
28+
Thumbs.db

backend-django/README.md

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
# backend-django
2+
3+
API REST Django pour l'application `media`.
4+
5+
## Stack
6+
7+
- Python
8+
- Django
9+
- Django REST Framework
10+
- PostgreSQL
11+
- pytest
12+
13+
## Base PostgreSQL
14+
15+
Le schéma PostgreSQL existe déjà.
16+
17+
Django ne crée pas les tables.
18+
19+
Configuration utilisée :
20+
21+
```text
22+
database: media
23+
user: postgres
24+
password: Trustno1
25+
host: localhost
26+
port: 5432
27+
```
28+
29+
## Installation
30+
31+
```bash
32+
python -m venv .venv
33+
.venv\Scripts\activate
34+
pip install -r requirements.txt
35+
```
36+
37+
## Vérification Django
38+
39+
```bash
40+
python manage.py check
41+
```
42+
43+
## Lancement
44+
45+
```bash
46+
python manage.py runserver
47+
```
48+
49+
## API
50+
51+
```text
52+
GET /api/health
53+
54+
GET /api/continents
55+
GET /api/continents/{id}
56+
57+
GET /api/countries
58+
GET /api/countries/{id}
59+
60+
GET /api/cities
61+
GET /api/cities/{id}
62+
63+
GET /api/persons
64+
GET /api/persons/{id}
65+
66+
GET /api/professions
67+
GET /api/professions/{id}
68+
69+
GET /api/media-types
70+
GET /api/media-types/{id}
71+
72+
GET /api/media
73+
GET /api/media/{id}
74+
```
75+
76+
## Tests
77+
78+
```bash
79+
pytest
80+
```
81+
82+
## Important
83+
84+
Ne pas exécuter :
85+
86+
```bash
87+
python manage.py makemigrations
88+
python manage.py migrate
89+
```
90+
91+
Les tables sont gérées directement dans PostgreSQL.

backend-django/config/__init__.py

Whitespace-only changes.

backend-django/config/asgi.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import os
2+
3+
from django.core.asgi import get_asgi_application
4+
5+
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "config.settings")
6+
7+
application = get_asgi_application()

backend-django/config/settings.py

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
from pathlib import Path
2+
3+
BASE_DIR = Path(__file__).resolve().parent.parent
4+
5+
SECRET_KEY = "django-insecure-ganatan-dev-key"
6+
7+
DEBUG = True
8+
9+
ALLOWED_HOSTS = []
10+
11+
INSTALLED_APPS = [
12+
"django.contrib.admin",
13+
"django.contrib.auth",
14+
"django.contrib.contenttypes",
15+
"django.contrib.sessions",
16+
"django.contrib.messages",
17+
"django.contrib.staticfiles",
18+
"rest_framework",
19+
"media",
20+
]
21+
22+
MIDDLEWARE = [
23+
"django.middleware.security.SecurityMiddleware",
24+
"django.contrib.sessions.middleware.SessionMiddleware",
25+
"django.middleware.common.CommonMiddleware",
26+
"django.middleware.csrf.CsrfViewMiddleware",
27+
"django.contrib.auth.middleware.AuthenticationMiddleware",
28+
"django.contrib.messages.middleware.MessageMiddleware",
29+
"django.middleware.clickjacking.XFrameOptionsMiddleware",
30+
]
31+
32+
ROOT_URLCONF = "config.urls"
33+
34+
TEMPLATES = [
35+
{
36+
"BACKEND": "django.template.backends.django.DjangoTemplates",
37+
"DIRS": [],
38+
"APP_DIRS": True,
39+
"OPTIONS": {
40+
"context_processors": [
41+
"django.template.context_processors.request",
42+
"django.contrib.auth.context_processors.auth",
43+
"django.contrib.messages.context_processors.messages",
44+
],
45+
},
46+
},
47+
]
48+
49+
WSGI_APPLICATION = "config.wsgi.application"
50+
51+
DATABASES = {
52+
"default": {
53+
"ENGINE": "django.db.backends.postgresql",
54+
"NAME": "media",
55+
"USER": "postgres",
56+
"PASSWORD": "Trustno1",
57+
"HOST": "localhost",
58+
"PORT": "5432",
59+
}
60+
}
61+
62+
LANGUAGE_CODE = "en-us"
63+
64+
TIME_ZONE = "UTC"
65+
66+
USE_I18N = True
67+
68+
USE_TZ = True
69+
70+
STATIC_URL = "static/"
71+
72+
DEFAULT_AUTO_FIELD = "django.db.models.BigAutoField"
73+
74+
REST_FRAMEWORK = {
75+
"DEFAULT_RENDERER_CLASSES": [
76+
"rest_framework.renderers.JSONRenderer",
77+
"rest_framework.renderers.BrowsableAPIRenderer",
78+
]
79+
}

backend-django/config/urls.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
from django.contrib import admin
2+
from django.urls import include, path
3+
4+
urlpatterns = [
5+
path("admin/", admin.site.urls),
6+
path("api/", include("media.urls")),
7+
]

backend-django/config/wsgi.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import os
2+
3+
from django.core.wsgi import get_wsgi_application
4+
5+
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "config.settings")
6+
7+
application = get_wsgi_application()

backend-django/manage.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#!/usr/bin/env python
2+
import os
3+
import sys
4+
5+
def main():
6+
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "config.settings")
7+
from django.core.management import execute_from_command_line
8+
execute_from_command_line(sys.argv)
9+
10+
if __name__ == "__main__":
11+
main()

backend-django/media/__init__.py

Whitespace-only changes.

backend-django/media/admin.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
from django.contrib import admin
2+
3+
from .models import City, Continent, Country, Media, MediaType, Person, Profession
4+
5+
admin.site.register(Continent)
6+
admin.site.register(Country)
7+
admin.site.register(City)
8+
admin.site.register(Person)
9+
admin.site.register(Profession)
10+
admin.site.register(MediaType)
11+
admin.site.register(Media)

0 commit comments

Comments
 (0)