Skip to content

Commit d573dcc

Browse files
committed
rest api with postgres django
0 parents  commit d573dcc

File tree

17 files changed

+376
-0
lines changed

17 files changed

+376
-0
lines changed

.env

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
POSTGRES_HOST=127.0.0.1
2+
POSTGRES_USER=postgres
3+
POSTGRES_PASSWORD=password123
4+
POSTGRES_DB=golang-gorm
5+
POSTGRES_PORT=6500
6+
7+
PGADMIN_DEFAULT_EMAIL=admin@admin.com
8+
PGADMIN_DEFAULT_PASSWORD=password123

.gitignore

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
venv/
2+
*.log
3+
*.pot
4+
*.pyc
5+
__pycache__
6+
db.sqlite3
7+
media

docker-compose.yml

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
services:
2+
postgres:
3+
image: postgres:latest
4+
container_name: postgres
5+
ports:
6+
- '6500:5432'
7+
volumes:
8+
- progresDB:/var/lib/postgresql/data
9+
env_file:
10+
- ./app.env
11+
pgAdmin:
12+
image: dpage/pgadmin4
13+
container_name: pgAdmin
14+
env_file:
15+
- ./app.env
16+
ports:
17+
- '5050:80'
18+
volumes:
19+
progresDB:

feedback/__init__.py

Whitespace-only changes.

feedback/asgi.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
"""
2+
ASGI config for feedback 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/5.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', 'feedback.settings')
15+
16+
application = get_asgi_application()

feedback/settings.py

Lines changed: 142 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,142 @@
1+
"""
2+
Django settings for feedback project.
3+
4+
Generated by 'django-admin startproject' using Django 5.1.3.
5+
6+
For more information on this file, see
7+
https://docs.djangoproject.com/en/5.1/topics/settings/
8+
9+
For the full list of settings and their values, see
10+
https://docs.djangoproject.com/en/5.1/ref/settings/
11+
"""
12+
13+
from pathlib import Path
14+
import os
15+
from dotenv import load_dotenv
16+
17+
# Build paths inside the project like this: BASE_DIR / 'subdir'.
18+
BASE_DIR = Path(__file__).resolve().parent.parent
19+
20+
21+
# Quick-start development settings - unsuitable for production
22+
# See https://docs.djangoproject.com/en/5.1/howto/deployment/checklist/
23+
24+
# SECURITY WARNING: keep the secret key used in production secret!
25+
SECRET_KEY = 'django-insecure-r#k+$x+n2s#87)^%^(*&wu^@k(_tm%(%x&vg_jnkcwim0f&n7q'
26+
27+
# SECURITY WARNING: don't run with debug turned on in production!
28+
DEBUG = True
29+
30+
ALLOWED_HOSTS = []
31+
CORS_ALLOWED_ORIGINS = [
32+
"http://localhost:3000"
33+
]
34+
CORS_ALLOW_CREDENTIALS = True
35+
36+
37+
38+
# Application definition
39+
40+
INSTALLED_APPS = [
41+
'django.contrib.admin',
42+
'django.contrib.auth',
43+
'django.contrib.contenttypes',
44+
'django.contrib.sessions',
45+
'django.contrib.messages',
46+
'django.contrib.staticfiles',
47+
'corsheaders',
48+
'feedback_api',
49+
'rest_framework',
50+
]
51+
52+
53+
MIDDLEWARE = [
54+
'django.middleware.security.SecurityMiddleware',
55+
'django.contrib.sessions.middleware.SessionMiddleware',
56+
'django.middleware.common.CommonMiddleware',
57+
'django.middleware.csrf.CsrfViewMiddleware',
58+
'django.contrib.auth.middleware.AuthenticationMiddleware',
59+
'django.contrib.messages.middleware.MessageMiddleware',
60+
'django.middleware.clickjacking.XFrameOptionsMiddleware',
61+
'corsheaders.middleware.CorsMiddleware',
62+
'django.middleware.common.CommonMiddleware',
63+
]
64+
65+
ROOT_URLCONF = 'feedback.urls'
66+
67+
TEMPLATES = [
68+
{
69+
'BACKEND': 'django.template.backends.django.DjangoTemplates',
70+
'DIRS': [],
71+
'APP_DIRS': True,
72+
'OPTIONS': {
73+
'context_processors': [
74+
'django.template.context_processors.debug',
75+
'django.template.context_processors.request',
76+
'django.contrib.auth.context_processors.auth',
77+
'django.contrib.messages.context_processors.messages',
78+
],
79+
},
80+
},
81+
]
82+
83+
WSGI_APPLICATION = 'feedback.wsgi.application'
84+
85+
86+
# Database
87+
# https://docs.djangoproject.com/en/5.1/ref/settings/#databases
88+
89+
load_dotenv()
90+
91+
DATABASES = {
92+
'default': {
93+
'ENGINE': 'django.db.backends.postgresql',
94+
'NAME': os.getenv('POSTGRES_DB'),
95+
'USER': os.getenv('POSTGRES_USER'),
96+
'PASSWORD': os.getenv('POSTGRES_PASSWORD'),
97+
'HOST': os.getenv('POSTGRES_HOST', 'localhost'),
98+
'PORT': os.getenv('POSTGRES_PORT', '5432'),
99+
}
100+
}
101+
102+
103+
# Password validation
104+
# https://docs.djangoproject.com/en/5.1/ref/settings/#auth-password-validators
105+
106+
AUTH_PASSWORD_VALIDATORS = [
107+
{
108+
'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
109+
},
110+
{
111+
'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
112+
},
113+
{
114+
'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',
115+
},
116+
{
117+
'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',
118+
},
119+
]
120+
121+
122+
# Internationalization
123+
# https://docs.djangoproject.com/en/5.1/topics/i18n/
124+
125+
LANGUAGE_CODE = 'en-us'
126+
127+
TIME_ZONE = 'UTC'
128+
129+
USE_I18N = True
130+
131+
USE_TZ = True
132+
133+
134+
# Static files (CSS, JavaScript, Images)
135+
# https://docs.djangoproject.com/en/5.1/howto/static-files/
136+
137+
STATIC_URL = 'static/'
138+
139+
# Default primary key field type
140+
# https://docs.djangoproject.com/en/5.1/ref/settings/#default-auto-field
141+
142+
DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField'

feedback/urls.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
"""
2+
URL configuration for feedback project.
3+
4+
The `urlpatterns` list routes URLs to views. For more information please see:
5+
https://docs.djangoproject.com/en/5.1/topics/http/urls/
6+
Examples:
7+
Function views
8+
1. Add an import: from my_app import views
9+
2. Add a URL to urlpatterns: path('', views.home, name='home')
10+
Class-based views
11+
1. Add an import: from other_app.views import Home
12+
2. Add a URL to urlpatterns: path('', Home.as_view(), name='home')
13+
Including another URLconf
14+
1. Import the include() function: from django.urls import include, path
15+
2. Add a URL to urlpatterns: path('blog/', include('blog.urls'))
16+
"""
17+
from django.contrib import admin
18+
from django.urls import path, include
19+
20+
urlpatterns = [
21+
path('admin/', admin.site.urls),
22+
path('api/feedbacks/', include('feedback_api.urls'))
23+
24+
]

feedback/wsgi.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
"""
2+
WSGI config for feedback 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/5.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', 'feedback.settings')
15+
16+
application = get_wsgi_application()

feedback_api/__init__.py

Whitespace-only changes.

feedback_api/admin.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
from django.contrib import admin
2+
3+
# Register your models here.

0 commit comments

Comments
 (0)