-
django conversations-list by FBVProject using python/Cloning Airbnb 2021. 4. 23. 16:55
url 설정
config/urls.py
urlpatterns = [ path("conversations/", include("conversations.urls", namespace="conversations")), ]
conversations/urls.py
from django.urls import path from . import views app_name = "conversations" urlpatterns = [ path( "conversation-list/", views.conversationList, name="conversation-list", ), ]
Client
pages/conversations/conversation_host_list.html
{% extends 'base.html' %} {% block page_title %} {{request.user}}'s Conversation List {% endblock page_title %} {% block content %} <div class="flex flex-col items-center justify-items-center"> <div class="w-10/12"> <div class="grid grid-cols-4 gap-4"> {% for conversation in conversations %} <a href="{% url 'conversations:conversation-detail' conversation.pk %}" class="border border-gray-500 p-6 rounded-lg flex justify-center items-center"> {% include 'mixins/conversation_avatars.html' with conversation=conversation %} </a> {% endfor %} </div> <div class="flex justify-center mt-20 itmes-center"> {% include 'mixins/page_number.html' with page=rooms %} </div> </div> </div> {% endblock content %}
FBV(Function Based View)
conversations/views.py
# conversations/views.py from django.shortcuts import redirect, reverse, render from django.core.paginator import Paginator from . import models as conversation_models from users import models as user_models def conversationList(request): qs = conversation_models.Conversation.objects.filter(participants=request.user) page = request.GET.get("page", 1) if page == "": page = 1 else: page = int(page) page_sector = ((page - 1) // 5) * 5 paginator = Paginator(qs, 12, orphans=6) conversations = paginator.get_page(page) return render( request, "pages/conversations/conversation_host_list.html", context={"conversations": conversations, "page_sector": page_sector}, )
참고 자료
- 노마드 코더의 Airbnb 클론 강의
소스 코드
github.com/zpskek/airbnb-clone-v3/commit/f1cb19f967710582f02546ed5dbb5fbfd007ba4d
'Project using python > Cloning Airbnb' 카테고리의 다른 글
django create-message by FBV (0) 2021.04.23 django conversation-list by FBV with ListView (0) 2021.04.23 django conversation-detail by CBV with DetailView (0) 2021.04.23 django fav-list by CBV with ListView (0) 2021.04.23 django conversations-detail by FBV (0) 2021.04.23