Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

코드 리뷰 #1

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
615 changes: 615 additions & 0 deletions .gitignore

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions page/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# TODO: 왜 __init__.py 파일이 필요한지 주석으로라도 적어주세요.
# 필요 없다면 지우는 편이 좋을 거 같습니다.
2 changes: 1 addition & 1 deletion page/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@


# Register your models here.
admin.site.register(Post)
admin.site.register(Post)
6 changes: 4 additions & 2 deletions page/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,13 @@
from django.conf import settings

# Create your models here.


class Post(models.Model):
title = models.CharField(max_length=50, default='')
update_date = models.DateTimeField(default=timezone.now)
text = models.TextField()
image = models.ImageField(upload_to = 'images/', blank = True, null = True)
image = models.ImageField(upload_to='images/', blank=True, null=True)

def __str__(self):
return self.title
return self.title
14 changes: 7 additions & 7 deletions page/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
from . import views

urlpatterns = [
path('', views.home, name = 'home'),
path('post/<int:post_id>', views.detail, name = 'detail'),
path('new/', views.new, name = 'new'),
path('create/', views.create, name = 'create'),
path('update/<int:post_id>', views.update, name = 'update'),
path('delete/<int:post_id>', views.delete, name = 'delete'),
]
path('', views.home, name='home'),
path('post/<int:post_id>', views.detail, name='detail'),
path('new/', views.new, name='new'),
path('create/', views.create, name='create'),
path('update/<int:post_id>', views.update, name='update'),
path('delete/<int:post_id>', views.delete, name='delete'),
]
22 changes: 15 additions & 7 deletions page/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,23 @@
from .models import Post

# Create your views here.
# TODO: 각각의 view가 어떤 걸 의미하는지 Docstring으로 적어주세요.


def home(request):
posts = Post.objects.all()
return render(request, 'home.html', {'posts':posts})
return render(request, 'home.html', {'posts': posts})


def detail(request, post_id):
post = get_object_or_404(Post, pk = post_id)
return render(request, 'detail.html', {'post':post})
post = get_object_or_404(Post, pk=post_id)
return render(request, 'detail.html', {'post': post})


def new(request):
return render(request, 'new.html')


def create(request):
if request.method == 'POST':
post = Post()
Expand All @@ -24,9 +30,10 @@ def create(request):
post.save()

return redirect('detail', post.id)



def update(request, post_id):
post = get_object_or_404(Post, pk = post_id)
post = get_object_or_404(Post, pk=post_id)

if request.method == 'POST':
if 'image' in request.FILES:
Expand All @@ -37,9 +44,10 @@ def update(request, post_id):
post.save()
return redirect('detail', post.id)
else:
return render(request, 'update.html', {'post':post})
return render(request, 'update.html', {'post': post})


def delete(request, post_id):
post = get_object_or_404(Post, pk = post_id)
post = get_object_or_404(Post, pk=post_id)
post.delete()
return redirect('home')
3 changes: 2 additions & 1 deletion sullivanwiki/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from pathlib import Path

# Build paths inside the project like this: BASE_DIR / 'subdir'.
# TODO: 각각의 설정이 어떤 것을 의미하는지 적어주세요.
BASE_DIR = Path(__file__).resolve().parent.parent


Expand Down Expand Up @@ -117,4 +118,4 @@

MEDIA_ROOT = os.path.join(BASE_DIR, 'media')

MEDIA_URL = '/media/'
MEDIA_URL = '/media/'
2 changes: 1 addition & 1 deletion sullivanwiki/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@
urlpatterns = [
path('admin/', admin.site.urls),
path('', include('page.urls')),
] + static(settings.MEDIA_URL, document_root = settings.MEDIA_ROOT)
] + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)