Skip to content

Commit

Permalink
5/16 박태범 likelion-hansung#27
Browse files Browse the repository at this point in the history
4주차 과제
  • Loading branch information
Beomtae committed May 16, 2023
1 parent 80515c9 commit 98926f9
Show file tree
Hide file tree
Showing 57 changed files with 1,512 additions and 0 deletions.
Empty file.
16 changes: 16 additions & 0 deletions [4주차]/박태범/liongram/config/asgi.py
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()
130 changes: 130 additions & 0 deletions [4주차]/박태범/liongram/config/settings.py
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'
19 changes: 19 additions & 0 deletions [4주차]/박태범/liongram/config/urls.py
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)
16 changes: 16 additions & 0 deletions [4주차]/박태범/liongram/config/wsgi.py
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()
22 changes: 22 additions & 0 deletions [4주차]/박태범/liongram/manage.py
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.
28 changes: 28 additions & 0 deletions [4주차]/박태범/liongram/posts/admin.py
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)
6 changes: 6 additions & 0 deletions [4주차]/박태범/liongram/posts/apps.py
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'
24 changes: 24 additions & 0 deletions [4주차]/박태범/liongram/posts/migrations/0001_initial.py
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='조회수')),
],
),
]
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.
17 changes: 17 additions & 0 deletions [4주차]/박태범/liongram/posts/models.py
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)
14 changes: 14 additions & 0 deletions [4주차]/박태범/liongram/posts/templates/cbv_view.html
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>
22 changes: 22 additions & 0 deletions [4주차]/박태범/liongram/posts/templates/view.html
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>
3 changes: 3 additions & 0 deletions [4주차]/박태범/liongram/posts/tests.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from django.test import TestCase

# Create your tests here.
13 changes: 13 additions & 0 deletions [4주차]/박태범/liongram/posts/urls.py
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"),
]
Loading

0 comments on commit 98926f9

Please sign in to comment.