diff --git a/apps/blog/utils.py b/apps/blog/utils.py index 9f568b7..afca9f0 100644 --- a/apps/blog/utils.py +++ b/apps/blog/utils.py @@ -16,20 +16,11 @@ def get_search_model_queryset( ) return search_query - # search_for_title = model_queryset.filter(title__icontains=search_query) - # if not search_for_title: - # search_for_content = model_queryset.filter(content__icontains=search_query) - # if not search_for_content: - # queryset = search_for_content - # else: - # queryset = search_for_content - # else: - # queryset = search_for_title - # return queryset + def get_pagination_obj(model_queryset: QuerySet, page: int = 1, size: int = 4) -> Page: - paginator = Paginator(model_queryset.order_by("id"), size) + paginator = Paginator(model_queryset.order_by("-created_at"), size) try: page_obj = paginator.page(page) diff --git a/apps/blog/views.py b/apps/blog/views.py index 32310c9..a4862b0 100644 --- a/apps/blog/views.py +++ b/apps/blog/views.py @@ -166,7 +166,7 @@ def get(self, request): context = { "title": "My posts", "template_htmx": self.template_htmx, - "posts": posts + "posts": posts.order_by("-created_at") } return render(request, self.template_name, context) diff --git a/templates/base.html b/templates/base.html index d338962..c9d7a0a 100644 --- a/templates/base.html +++ b/templates/base.html @@ -21,22 +21,7 @@ {% include 'components/headers.html' %}
- - {% if messages %} - {% for message in messages %} - {% if message.tags == 'error' %} - - {% else %} - - {% endif %} - {% endfor %} - {% endif %} + {% include 'components/messages.html' %}
diff --git a/templates/blog/post_confirm_delete.html b/templates/blog/post_confirm_delete.html index c311ffc..e55ca90 100644 --- a/templates/blog/post_confirm_delete.html +++ b/templates/blog/post_confirm_delete.html @@ -1,9 +1,4 @@ -{% extends 'base.html' %} -{% load static %} -{% block title %} Post Confirm Delete {% endblock %} - -{% block content %}
@@ -16,7 +11,13 @@

"{{ post.title }}" ?

- Cancel + Cancel
@@ -24,6 +25,5 @@

"{{ post.title }}" ?

{% include 'components/latest_posts.html' %}
-{% endblock %} diff --git a/templates/blog/post_detail.html b/templates/blog/post_detail.html index 318f66a..e61e3c3 100644 --- a/templates/blog/post_detail.html +++ b/templates/blog/post_detail.html @@ -5,7 +5,14 @@

{{ post.title }}

- +

{{ post.description }}

@@ -19,19 +26,34 @@

{{ post.title }}

- + {% if request.user.is_authenticated %} {% if post|check_like:request.user %} ({{ post.like_count }}) @@ -45,7 +67,12 @@

{{ post.title }}

- + {% if request.user.is_authenticated %} {% if post|check_dislike:request.user %} ({{ post.dislike_count }}) @@ -61,13 +88,30 @@

{{ post.title }}

{% if request.user == post.author %}
{% endif %}
-
+ {% csrf_token %}
diff --git a/templates/blog/post_update.html b/templates/blog/post_update.html index 2cefd49..7099150 100644 --- a/templates/blog/post_update.html +++ b/templates/blog/post_update.html @@ -1,7 +1,9 @@
- + {% csrf_token %}
Update post: {{ post.title}} @@ -26,7 +28,12 @@
- Cancel + Cancel
diff --git a/templates/blog/profile.html b/templates/blog/profile.html index ad6c7bf..6b4ceff 100644 --- a/templates/blog/profile.html +++ b/templates/blog/profile.html @@ -33,7 +33,12 @@

{% if request.user == user %} {% endif %}
@@ -56,7 +61,13 @@

{{ post.title }}

{{ post.publisher_at }}

{{ post.description|truncatewords_html:30 }}

- Continue reading + Continue reading
{{ post.watching }} {{ post.like_count }} diff --git a/templates/blog/user_posts.html b/templates/blog/user_posts.html index 51e3859..02c878a 100644 --- a/templates/blog/user_posts.html +++ b/templates/blog/user_posts.html @@ -1,18 +1,22 @@
-
-
+
@@ -34,7 +38,12 @@
{{ message }}

{{ post.title }}

{{ post.publisher_at }}

{{ post.description|truncatewords_html:30 }}

- Continue reading + Continue reading
diff --git a/templates/components/headers.html b/templates/components/headers.html index 25dc244..b6416c9 100644 --- a/templates/components/headers.html +++ b/templates/components/headers.html @@ -146,6 +146,10 @@ hx-triget="#main-content" > +
+ + +
diff --git a/templates/components/messages.html b/templates/components/messages.html new file mode 100644 index 0000000..ecf4eff --- /dev/null +++ b/templates/components/messages.html @@ -0,0 +1,17 @@ +{% if messages %} +
+ {% for message in messages %} + {% if message.tags == 'error' %} + + {% else %} + + {% endif %} + {% endfor %} +
+{% endif %} \ No newline at end of file