forked from likelion-hansung/Backend
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
4주차 과제
- Loading branch information
Showing
57 changed files
with
1,512 additions
and
0 deletions.
There are no files selected for viewing
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
""" | ||
ASGI config for config project. | ||
It exposes the ASGI callable as a module-level variable named ``application``. | ||
For more information on this file, see | ||
https://docs.djangoproject.com/en/4.2/howto/deployment/asgi/ | ||
""" | ||
|
||
import os | ||
|
||
from django.core.asgi import get_asgi_application | ||
|
||
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'config.settings') | ||
|
||
application = get_asgi_application() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,130 @@ | ||
""" | ||
Django settings for config project. | ||
Generated by 'django-admin startproject' using Django 4.2.1. | ||
For more information on this file, see | ||
https://docs.djangoproject.com/en/4.2/topics/settings/ | ||
For the full list of settings and their values, see | ||
https://docs.djangoproject.com/en/4.2/ref/settings/ | ||
""" | ||
|
||
from pathlib import Path | ||
|
||
# Build paths inside the project like this: BASE_DIR / 'subdir'. | ||
BASE_DIR = Path(__file__).resolve().parent.parent | ||
|
||
|
||
# Quick-start development settings - unsuitable for production | ||
# See https://docs.djangoproject.com/en/4.2/howto/deployment/checklist/ | ||
|
||
# SECURITY WARNING: keep the secret key used in production secret! | ||
SECRET_KEY = 'django-insecure-fp*=rdp8^)5y^g(o*1$qwk*y7@x+qf0f_bqb&f%to^c8=2y6ip' | ||
|
||
# SECURITY WARNING: don't run with debug turned on in production! | ||
DEBUG = True | ||
|
||
ALLOWED_HOSTS = [] | ||
|
||
|
||
# Application definition | ||
|
||
INSTALLED_APPS = [ | ||
'django.contrib.admin', | ||
'django.contrib.auth', | ||
'django.contrib.contenttypes', | ||
'django.contrib.sessions', | ||
'django.contrib.messages', | ||
'django.contrib.staticfiles', | ||
'posts', | ||
] | ||
|
||
MIDDLEWARE = [ | ||
'django.middleware.security.SecurityMiddleware', | ||
'django.contrib.sessions.middleware.SessionMiddleware', | ||
'django.middleware.common.CommonMiddleware', | ||
'django.middleware.csrf.CsrfViewMiddleware', | ||
'django.contrib.auth.middleware.AuthenticationMiddleware', | ||
'django.contrib.messages.middleware.MessageMiddleware', | ||
'django.middleware.clickjacking.XFrameOptionsMiddleware', | ||
] | ||
|
||
ROOT_URLCONF = 'config.urls' | ||
|
||
TEMPLATES = [ | ||
{ | ||
'BACKEND': 'django.template.backends.django.DjangoTemplates', | ||
'DIRS': [BASE_DIR/'templates'], | ||
'APP_DIRS': True, | ||
'OPTIONS': { | ||
'context_processors': [ | ||
'django.template.context_processors.debug', | ||
'django.template.context_processors.request', | ||
'django.contrib.auth.context_processors.auth', | ||
'django.contrib.messages.context_processors.messages', | ||
], | ||
}, | ||
}, | ||
] | ||
|
||
WSGI_APPLICATION = 'config.wsgi.application' | ||
|
||
|
||
# Database | ||
# https://docs.djangoproject.com/en/4.2/ref/settings/#databases | ||
|
||
DATABASES = { | ||
'default': { | ||
'ENGINE': 'django.db.backends.sqlite3', | ||
'NAME': BASE_DIR / 'db.sqlite3', | ||
} | ||
} | ||
|
||
|
||
# Password validation | ||
# https://docs.djangoproject.com/en/4.2/ref/settings/#auth-password-validators | ||
|
||
AUTH_PASSWORD_VALIDATORS = [ | ||
{ | ||
'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator', | ||
}, | ||
{ | ||
'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator', | ||
}, | ||
{ | ||
'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator', | ||
}, | ||
{ | ||
'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator', | ||
}, | ||
] | ||
|
||
|
||
# Internationalization | ||
# https://docs.djangoproject.com/en/4.2/topics/i18n/ | ||
|
||
LANGUAGE_CODE = 'ko-kr' | ||
|
||
TIME_ZONE = 'UTC' | ||
|
||
USE_I18N = True | ||
|
||
USE_TZ = True | ||
|
||
|
||
# Static files (CSS, JavaScript, Images) | ||
# https://docs.djangoproject.com/en/4.2/howto/static-files/ | ||
|
||
STATIC_URL = 'static/' | ||
STATICFILES_DIRS = [ | ||
BASE_DIR / 'static' | ||
] | ||
|
||
# Default primary key field type | ||
# https://docs.djangoproject.com/en/4.2/ref/settings/#default-auto-field | ||
|
||
DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField' | ||
|
||
MEDIA_URL='media/' | ||
MEDIA_ROOT = BASE_DIR / 'media' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
from django.contrib import admin | ||
from django.conf import settings | ||
from django.conf.urls.static import static | ||
from django.urls import include, path | ||
|
||
from posts.views import class_view, url_view,url_parameter_view,function_view,index | ||
|
||
urlpatterns = [ | ||
path('admin/', admin.site.urls), | ||
path('url/', url_view), | ||
path('url/<str:username>/',url_parameter_view), | ||
path('fbv/', function_view), | ||
path('cbv/', class_view.as_view(), name='cbv'), | ||
|
||
path('', index, name='index'), | ||
path('posts/', include('posts.urls', namespace='posts')), | ||
] | ||
|
||
urlpatterns += static(settings.MEDIA_URL, document_root = settings.MEDIA_ROOT) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
""" | ||
WSGI config for config project. | ||
It exposes the WSGI callable as a module-level variable named ``application``. | ||
For more information on this file, see | ||
https://docs.djangoproject.com/en/4.2/howto/deployment/wsgi/ | ||
""" | ||
|
||
import os | ||
|
||
from django.core.wsgi import get_wsgi_application | ||
|
||
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'config.settings') | ||
|
||
application = get_wsgi_application() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
#!/usr/bin/env python | ||
"""Django's command-line utility for administrative tasks.""" | ||
import os | ||
import sys | ||
|
||
|
||
def main(): | ||
"""Run administrative tasks.""" | ||
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'config.settings') | ||
try: | ||
from django.core.management import execute_from_command_line | ||
except ImportError as exc: | ||
raise ImportError( | ||
"Couldn't import Django. Are you sure it's installed and " | ||
"available on your PYTHONPATH environment variable? Did you " | ||
"forget to activate a virtual environment?" | ||
) from exc | ||
execute_from_command_line(sys.argv) | ||
|
||
|
||
if __name__ == '__main__': | ||
main() |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
from django.contrib import admin | ||
from .models import Post,Comment | ||
# Register your models here. | ||
|
||
class CommentInline(admin.TabularInline): | ||
model = Comment | ||
extra = 5 | ||
min_num = 3 | ||
max_num = 5 | ||
verbose_name = '댓글' | ||
verbose_name_plural = '댓글' | ||
|
||
@admin.register(Post) | ||
class PostModelAdmin(admin.ModelAdmin): | ||
list_display = ('id','image','content','created_at','view_count','writer') | ||
list_filter = ('created_at',) | ||
search_fields = ('id',) | ||
search_help_text = '게시판 번호, 작성자 검색이 가능합니다.' | ||
inlines = [CommentInline] | ||
|
||
actions = ['make_published'] | ||
|
||
def make_published(modeladmin, request, queryset): | ||
for item in queryset: | ||
item.content='운영 규정 위반으로 인한 게시글 삭제 처리.' | ||
item.save() | ||
|
||
#admin.site.register(Comment) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
from django.apps import AppConfig | ||
|
||
|
||
class PostsConfig(AppConfig): | ||
default_auto_field = 'django.db.models.BigAutoField' | ||
name = 'posts' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
# Generated by Django 4.2.1 on 2023-05-10 07:42 | ||
|
||
from django.db import migrations, models | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
initial = True | ||
|
||
dependencies = [ | ||
] | ||
|
||
operations = [ | ||
migrations.CreateModel( | ||
name='Post', | ||
fields=[ | ||
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), | ||
('image', models.IntegerField(verbose_name='이미지')), | ||
('content', models.TextField(verbose_name='내용')), | ||
('created_at', models.DateTimeField(verbose_name='작성일')), | ||
('view_count', models.IntegerField(verbose_name='조회수')), | ||
], | ||
), | ||
] |
46 changes: 46 additions & 0 deletions
46
...gram/posts/migrations/0002_post_writer_alter_post_created_at_alter_post_image_and_more.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
# Generated by Django 4.2.1 on 2023-05-10 08:26 | ||
|
||
from django.conf import settings | ||
from django.db import migrations, models | ||
import django.db.models.deletion | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
migrations.swappable_dependency(settings.AUTH_USER_MODEL), | ||
('posts', '0001_initial'), | ||
] | ||
|
||
operations = [ | ||
migrations.AddField( | ||
model_name='post', | ||
name='writer', | ||
field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL), | ||
), | ||
migrations.AlterField( | ||
model_name='post', | ||
name='created_at', | ||
field=models.DateTimeField(auto_now_add=True, verbose_name='작성일'), | ||
), | ||
migrations.AlterField( | ||
model_name='post', | ||
name='image', | ||
field=models.IntegerField(blank=True, null=True, verbose_name='이미지'), | ||
), | ||
migrations.AlterField( | ||
model_name='post', | ||
name='view_count', | ||
field=models.IntegerField(default=0, verbose_name='조회수'), | ||
), | ||
migrations.CreateModel( | ||
name='Comment', | ||
fields=[ | ||
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), | ||
('content', models.TextField(verbose_name='내용')), | ||
('created_at', models.DateTimeField(verbose_name='작성일')), | ||
('post', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='posts.post')), | ||
('writer', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL)), | ||
], | ||
), | ||
] |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
from django.db import models | ||
from django.contrib.auth import get_user_model | ||
|
||
User = get_user_model() | ||
|
||
class Post(models.Model): | ||
image = models.ImageField(verbose_name='이미지',null=True, blank=True) | ||
content = models.TextField(verbose_name='내용') | ||
created_at = models.DateTimeField(verbose_name='작성일', auto_now_add=True) | ||
view_count = models.IntegerField(verbose_name='조회수', default=0) | ||
writer = models.ForeignKey(to=User, on_delete=models.CASCADE,null=True, blank=True) | ||
|
||
class Comment(models.Model): | ||
content = models.TextField(verbose_name='내용') | ||
created_at = models.DateTimeField(verbose_name='작성일', auto_now_add=True) | ||
post = models.ForeignKey(to='Post', on_delete=models.CASCADE) | ||
writer = models.ForeignKey(to=User, on_delete=models.CASCADE,null=True, blank=True) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="UTF-8"> | ||
<meta http-equiv="X-UA-Compatible" content="IE=edge"> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | ||
<title>Document</title> | ||
</head> | ||
<body> | ||
{% for object in object_list %} | ||
{{ object }} | ||
{% endfor %} | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="UTF-8"> | ||
<meta http-equiv="X-UA-Compatible" content="IE=edge"> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | ||
<title>Document</title> | ||
</head> | ||
<body> | ||
<a href="/fbv/">새로고침</a><br> | ||
|
||
<form action="" method="GET"> | ||
<input type="text" name="var"> | ||
<input type="submit" value="GET 제출"> | ||
</form> | ||
|
||
<form action="" method="POST"> {% csrf_token%} | ||
<input type="text" name="var"> | ||
<input type="submit" value="POST 제출"> | ||
</form> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
from django.test import TestCase | ||
|
||
# Create your tests here. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
from django.urls import path | ||
|
||
from .views import post_list_view,post_create_view,post_update_view,post_detail_view,post_delete_view | ||
|
||
app_name='posts' #html 에서 url을 name으로 설정할때 필요 posts:post-create 등 | ||
|
||
urlpatterns=[ | ||
path('', post_list_view, name='post-list'), | ||
path('new/', post_create_view, name='post-create'), | ||
path('edit/<int:id>', post_update_view, name='post-update'), | ||
path('<int:id>/', post_detail_view, name='post-detail'), | ||
path('delete/<int:id>', post_delete_view, name="post-delete"), | ||
] |
Oops, something went wrong.