Skip to content
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
Empty file.
3 changes: 3 additions & 0 deletions django_project/accounts/admin.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from django.contrib import admin

# Register your models here.
6 changes: 6 additions & 0 deletions django_project/accounts/apps.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
from django.apps import AppConfig


class AccountsConfig(AppConfig):
default_auto_field = 'django.db.models.BigAutoField'
name = 'accounts'
5 changes: 5 additions & 0 deletions django_project/accounts/models.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
from django.db import models
from django.contrib.auth.models import AbstractUser

class User(AbstractUser):
phone = models.CharField(max_length=11)
18 changes: 18 additions & 0 deletions django_project/accounts/templates/login_form.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{% extends "base.html" %}
{% block content %}
{% load static %}
<link href="{% static 'css/login.css' %}" rel="stylesheet" />
<section id="section" class="py-5">
<div class="container px-4 px-lg-5 mt-5">
<div class="row gx-4 gx-lg-5 row-cols-2 row-cols-md-3 row-cols-xl-4 justify-content-center">
<form id='form' method="POST">
{% csrf_token %}
<input type="text" name="id" placeholder="ID"><br>
<input type="text" name="password" placeholder="PW"><br>
<input id='skhbutton' type="submit" class="fadeIn fourth" value="Login">
</form>
</div>
</div>
</section>

{% endblock %}
20 changes: 20 additions & 0 deletions django_project/accounts/templates/signup.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{% extends "base.html" %}
{% block content %}
{% load static %}
<link href="{% static 'css/login.css' %}" rel="stylesheet" />
<section class="py-5" style="background-color: white;">
<div class="container px-4 px-lg-5 mt-5">
<div class="row gx-4 gx-lg-5 row-cols-2 row-cols-md-3 row-cols-xl-4 justify-content-center">
<form id='form'>
<form id='skhform' method="POST">
{% csrf_token %}
<input type="text" name="id" placeholder="ID"><br>
<input type="text" name="password" placeholder="PW"><br>
<input type="text" name="phone" placeholder="PHONE"><br>
<input id='skhbutton' type="submit" class="fadeIn fourth" value="Sign-up">
</form>
</div>
</div>
</section>

{% endblock %}
3 changes: 3 additions & 0 deletions django_project/accounts/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.
8 changes: 8 additions & 0 deletions django_project/accounts/urls.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
from django.urls import path
from . import views

urlpatterns = [
path('login/', views.login, name='login'),
path('signup/', views.signup, name='signup'),
path('logout', views.logout, name='logout')
]
30 changes: 30 additions & 0 deletions django_project/accounts/views.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
from django.shortcuts import render, redirect
from django.contrib import auth
from django.contrib.auth import get_user_model

User = get_user_model()

def login(request):
if request.method == 'POST':
userid = request.POST['id']
password = request.POST['password']
user = auth.authenticate(request, username=userid, password=password)
if user is not None:
auth.login(request, user)
return redirect('list_page')
else:
return render(request, 'login_form.html')
else: #GET
return render(request, 'login_form.html')

def signup(request):
if request.method == 'POST':
user = User.objects.create_user(username=request.POST['id'], password = request.POST['password'], phone = request.POST['phone'])
auth.login(request, user)
return redirect('list_page')
else:
return render(request, 'signup.html')

def logout(request):
auth.logout(request)
return redirect('list_page')
7 changes: 6 additions & 1 deletion django_project/django_project/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@

'shopping',
'store',
'accounts',
]

MIDDLEWARE = [
Expand Down Expand Up @@ -132,4 +133,8 @@
# media

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

# custom user model

AUTH_USER_MODEL = 'accounts.User'
2 changes: 2 additions & 0 deletions django_project/django_project/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
path('admin/', admin.site.urls),
path('shopping/', include('shopping.urls')),
path('store/', include('store.urls')),
path('accounts/', include('accounts.urls'))

]

if settings.DEBUG:
Expand Down
10 changes: 9 additions & 1 deletion django_project/shopping/templates/base.html
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,15 @@
<div class="collapse navbar-collapse" id="navbarSupportedContent">
<ul class="navbar-nav me-auto mb-2 mb-lg-0 ms-lg-4">
<li class="nav-item"><a class="nav-link active" aria-current="page" href="{% url 'list_page' %}">Home</a></li>
<li class="nav-item"><a class="nav-link" href="#!">Post</a></li>
<li class="nav-item"><a class="nav-link" href="{% url 'modelformcreate' %}">Post</a></li>
{% if user.is_authenticated %}
<li class="nav-item"><a class="nav-link" href="{% url 'logout' %}">Logout</a></li>
{% else %}
<li class="nav-item"><a class="nav-link" href="{% url 'signup' %}">Sign-up</a></li>
<li class="nav-item"><a class="nav-link" href="{% url 'login' %}">Login</a></li>
{% endif %}
{% block search %}
{% endblock %}
</ul>
</div>
</div>
Expand Down
56 changes: 55 additions & 1 deletion django_project/shopping/templates/index.html
Original file line number Diff line number Diff line change
@@ -1,11 +1,31 @@
{% extends "base.html" %}

{% block search %}
<form action="{% url 'search_item' %}" method="POST">
{% csrf_token %}
<input type="text" name="search" placeholder="Search">
<input type="submit" value="검색">
</form>
{% endblock %}

{% block content %}
<!-- Header-->
<header class="bg-dark py-5" style="background-color: whites;">
<div class="container px-4 px-lg-5 my-5">
<div class="text-center text-white">
<h1 class="display-4 fw-bolder">My Shopping List</h1>
<p class="lead fw-normal text-white-50 mb-0">쇼핑할 물건의 목록을 반환하는 페이지입니다</p>
<br>
<div class="btn-group">
<button type="button" class="btn btn-secondary dropdown-toggle" data-bs-toggle="dropdown" aria-expanded="false">
정렬기준
</button>
<ul class="dropdown-menu">
<li><a class="dropdown-item" href="?sorting=descending-price">높은 가격 순</a></li>
<li><a class="dropdown-item" href="?sorting=ascending-price">낮은 가격 순</a></li>
<li><a class="dropdown-item" href="?sorting=name">이름</a></li>
</ul>
</div>
</p>
</div>
</div>
Expand All @@ -14,7 +34,7 @@ <h1 class="display-4 fw-bolder">My Shopping List</h1>
<section class="py-5" style="background-color: white;">
<div class="container px-4 px-lg-5 mt-5">
<div class="row gx-4 gx-lg-5 row-cols-2 row-cols-md-3 row-cols-xl-4 justify-content-center">
{% for item in item_list %}
{% for item in paginated_list %}
<div class="col mb-5">
<a style="color:inherit; text-decoration:none;" href="{% url 'detail_page' item.pk %}">
<div class="card h-100">
Expand Down Expand Up @@ -46,5 +66,39 @@ <h5 class="fw-bolder">{{ item.name }}</h5>
{% endfor %}
</div>
</div>
<ul class="pagination" style="justify-content: center;">
<!-- 이전페이지 -->
{% if paginated_list.has_previous %}
<li class="page-item">
<a class="page-link" href="?page={{ paginated_list.previous_page_number }}&sorting={{ sorting }}" aria-label="Previous">
<span aria-hidden="true">&laquo;</span>
</a>
</li>
{% else %}
<li class="page-item disabled"></li>
{% endif %}
<!-- 페이지리스트 -->
{% for page_number in paginated_list.paginator.page_range %}
{% if page_number == paginated_list.number %}
<li class="page-item active" aria-current="page">
<a class="page-link" href="?page={{ page_number }}&sorting={{ sorting }}">{{ page_number }}</a>
</li>
{% else %}
<li class="page-item">
<a class="page-link" href="?page={{ page_number }}&sorting={{ sorting }}">{{ page_number }}</a>
</li>
{% endif %}
{% endfor %}
<!-- 다음페이지 -->
{% if paginated_list.has_next %}
<li class="page-item">
<a class="page-link" href="?page={{ paginated_list.next_page_number }}&sorting={{ sorting }}" aria-label="Next">
<span aria-hidden="true">&raquo;</span>
</a>
</li>
{% else %}
<li class="page-item disabled"></li>
{% endif %}
</ul>
</section>
{% endblock %}
58 changes: 58 additions & 0 deletions django_project/shopping/templates/search.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
{% extends "base.html" %}

{% block search %}
<form action="{% url 'search_item' %}" method="POST">
{% csrf_token %}
<input type="text" name="search" placeholder="Search">
<input type="submit" value="검색">
</form>
{% endblock %}

{% block content %}
<!-- Header-->
<header class="bg-dark py-5" style="background-color: whites;">
<div class="container px-4 px-lg-5 my-5">
<div class="text-center text-white">
<h1 class="display-4 fw-bolder">Search</h1>
<p class="lead fw-normal text-white-50 mb-0">검색 결과를 반환하는 페이지입니다</p>
</div>
</div>
</header>
<!-- Section-->
<section class="py-5" style="background-color: white;">
<div class="container px-4 px-lg-5 mt-5">
<div class="row gx-4 gx-lg-5 row-cols-2 row-cols-md-3 row-cols-xl-4 justify-content-center">
{% for item in item_list %}
<div class="col mb-5">
<a style="color:inherit; text-decoration:none;" href="{% url 'detail_page' item.pk %}">
<div class="card h-100">
<!-- Product image-->
{% if item.image %}
<img class="card-img-top" src="{{ item.image.url }}" alt="..." />
{% else %}
<img class="card-img-top" src="https://dummyimage.com/450x300/dee2e6/6c757d.jpg" alt="..." />
{% endif %}
<!-- Product details-->
<div class="card-body p-4">
<div class="text-center">
<!-- Product name-->
<h5 class="fw-bolder">{{ item.name }}</h5>
<!-- Product price-->
{{ item.price }}<br>
{{ item.count }}<br>
{{ item.store }}<br>
{{ item.pk }}<br>
<hr>
{{ item.store.pk }}<br>
{{ item.store.name }}<br>
{{ item.store.address }}
</div>
</div>
</div>
</a>
</div>
{% endfor %}
</div>
</div>
</section>
{% endblock %}
1 change: 1 addition & 0 deletions django_project/shopping/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,5 @@
path('formcreate/', views.formcreate, name='formcreate'),
# django modelform을 이용해 쇼핑 아이템(Shopping) 객체 만들기
path('modelformcreate/', views.modelformcreate, name='modelformcreate'),
path('search/', views.search, name='search_item'),
]
25 changes: 22 additions & 3 deletions django_project/shopping/views.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,28 @@
from django.shortcuts import get_object_or_404, render, redirect
from django.contrib.auth.decorators import login_required
from .models import Shopping
from store.models import Store
from .forms import ShoppingForm, ShoppingModelForm
from django.core.paginator import Paginator

def shopping_list(request):
qs = Shopping.objects.all()
return render(request, 'index.html', {'item_list': qs,})
sort_criteria = request.GET.get('sorting', 'descending-price')
if sort_criteria == 'descending-price':
qs = Shopping.objects.order_by('-price')
elif sort_criteria == 'ascending-price':
qs = Shopping.objects.order_by('price')
elif sort_criteria == 'name':
qs = Shopping.objects.order_by('name')
page = request.GET.get('page', '1')
paginator = Paginator(qs, '2') #Paginator(분할될 객체, 페이지 당 담길 객체수)
paginated_qs = paginator.get_page(page)
return render(request, 'index.html', {'paginated_list': paginated_qs, 'sorting': sort_criteria})

def search(request):
oq = request.POST['search']
qs = Shopping.objects.filter(name__contains=oq)
return render(request,'search.html', {'item_list': qs})


def detail(request, pk):
item = get_object_or_404(Shopping, pk=pk)
Expand Down Expand Up @@ -39,6 +56,7 @@ def formcreate(request):
form = ShoppingForm()
return render(request, 'form_create.html', {'form':form})

@login_required
def modelformcreate(request):
if request.method == 'POST':
form = ShoppingModelForm(request.POST)
Expand All @@ -47,4 +65,5 @@ def modelformcreate(request):
return redirect('list_page')
else:
form = ShoppingModelForm()
return render(request, 'form_create.html', {'form':form})
return render(request, 'form_create.html', {'form':form})

26 changes: 26 additions & 0 deletions django_project/static/css/login.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#section {
background-color: white;
}

#form {
border : 2px solid #eee;
border-radius: 15px;
padding: 50px;
}
#form input {
margin: 10px 0;
width: 100%;
border-radius: 5px;
padding: 5px;
text-indent: 10px;
}
#skhbutton {
background-color: rgba(255, 128, 0, 0.7);
color:white;
border: none;
border-bottom: 4px solid rgba(255,128,0,1);
}
#skhbutton:active{
border-bottom: none;
border-top: 4px solid white;
}