diff --git a/apps/back/consumers.py b/apps/back/consumers.py index b51afdd..7e5366b 100644 --- a/apps/back/consumers.py +++ b/apps/back/consumers.py @@ -31,7 +31,12 @@ class BlogConsumer(WebsocketConsumer): # Database if template == "partials/blog/all_articles.html": - data["posts"] = Post.objects.all()[:5] + pag = data['pag'] if 'pag' in data else 1 + amount = 3 + start = pag - 1 + end = start + amount + data["posts"] = Post.objects.all()[start:end] + data['pag'] = pag if template == "partials/blog/single.html": data["post"] = Post.objects.get(data['id']) diff --git a/apps/front/templates/layouts/main.html b/apps/front/templates/layouts/main.html index edfd0f6..7490272 100644 --- a/apps/front/templates/layouts/main.html +++ b/apps/front/templates/layouts/main.html @@ -26,24 +26,7 @@
-
- {% for post in posts %} -
-

{{ post.title }}

-

Author: {{ post.author }}

-

-
-
- {% endfor %} -
- + {% include 'partials/blog/all_articles.html' %}
\ No newline at end of file + + // Paginator + pagPrevious = document.querySelector('#pag-previous'); + pagNext = document.querySelector('#pag-next'); + + pagPrevious.addEventListener('click', (event) => { + event.preventDefault(); + document.$CHAT_SOCKET.send(JSON.stringify({ + selector: "#main", + template: "partials/blog/all_articles.html", + data: { + pag: {% if pag > 1 %}{{ pag }} - 1{% else %}1{% endif %} + } + })) + }); + + + pagNext.addEventListener('click', (event) => { + event.preventDefault(); + document.$CHAT_SOCKET.send(JSON.stringify({ + selector: "#main", + template: "partials/blog/all_articles.html", + data: { + pag: {{ pag }} + 1 + } + })) + }); + + + + diff --git a/apps/front/views.py b/apps/front/views.py index d002238..c19583a 100644 --- a/apps/front/views.py +++ b/apps/front/views.py @@ -5,5 +5,6 @@ import uuid def all_articles(request): return render(request, 'layouts/main.html', { "CHANNEL": uuid.uuid4().hex[:20].upper(), - "posts": Post.objects.all()[:5] + "posts": Post.objects.all()[:3], + "pag": 1 }) diff --git a/db.sqlite3 b/db.sqlite3 index cf30280..ca8d398 100644 Binary files a/db.sqlite3 and b/db.sqlite3 differ