728x90
반응형
1. Create / Detail / List View (Update / delete)
2. Success_url to related Project
3. Login_required to CreateView
4. Model : title / description / image / created_at
개발 순서는 MVT 순서로 습관을 들이자.
(setting 과 url 설정)
1
projectapp 시작
2
settings.py
3
urls.py
4
projectapp/urls.py 생성
: app_name 지정, view 만들고 라우팅할 urlpattern form
app_name = 'projectapp'
urlpatterns = [
]
(M: model)
5
models.py
: title / description / image / created_at
* model 만든 이후에는 makemigrations, migrate
6
forms.py: model을 form으로 변환하자(ModelForm)
(V: view)
7
views.py
: Create / Detail / List View
8
projectapp/urls.py 라우팅
- ProjectListView
- ProjectCreateView
- ProjectDetailView
(T: templates)
9
templates/projectapp/create.html, detail.html, list.html
10
snippets/card_project.html
<div style="display: block; text-align: center">
<img src="{{ project.image.url }}" alt="">
<h5 class="mt-2" style="font-family: 'NanumSquareB'">
{{ project.title | truncatechars:7 }}
</h5>
</div>
* truncatechars:7 는 7자 이후는 생략표시하기 위함이다.
11
snippets/pagination.html 수정
: url이 articleapp:list 로 고정되어있다.
<div style="text-align: center; margin: 1rem 0;">
{% if page_obj.has_previous %}
<a href="{% url 'articleapp:list' %}?page={{ page_obj.previous_page_number }}"
class="btn btn-secondary rounded-pill">
{{ page_obj.previous_page_number }}
</a>
{% endif %}
<a href="{% url 'articleapp:list' %}?page={{ page_obj.number }}"
class="btn btn-secondary rounded-pill active">
{{ page_obj.number }}
</a>
{% if page_obj.has_next %}
<a href="{% url 'articleapp:list' %}?page={{ page_obj.next_page_number }}"
class="btn btn-secondary rounded-pill">
{{ page_obj.next_page_number }}
</a>
{% endif %}
</div>
이걸 없애주면
<div style="text-align: center; margin: 1rem 0;">
{% if page_obj.has_previous %}
<a href="?page={{ page_obj.previous_page_number }}"
class="btn btn-secondary rounded-pill">
{{ page_obj.previous_page_number }}
</a>
{% endif %}
<a href="?page={{ page_obj.number }}"
class="btn btn-secondary rounded-pill active">
{{ page_obj.number }}
</a>
{% if page_obj.has_next %}
<a href="?page={{ page_obj.next_page_number }}"
class="btn btn-secondary rounded-pill">
{{ page_obj.next_page_number }}
</a>
{% endif %}
</div>
어떤 페이지에서 pagination을 불러오더라도 작동한다. (뒤에 get paramerter만 변동)
728x90
반응형
'웹 프로그래밍' 카테고리의 다른 글
[pinterest clone (33)] RedirectView를 통한 subscribeapp (0) | 2021.05.03 |
---|---|
[pinterest clone (33)] MultipleObjectMixin을 통한 Projectapp 구현 (0) | 2021.05.03 |
[pinterest clone (31)] 모바일 디버깅, 반응형 레이아웃 (0) | 2021.05.02 |
[pinterest clone (30)] commentapp 구현과 Mixin (0) | 2021.05.02 |
[pinterest clone (29)] ListView, Pagination 적용 (0) | 2021.05.01 |