Create: paginations

This commit is contained in:
Stepan Zhukovsky 2023-07-29 16:36:08 +09:00
parent 96ae8647e1
commit e2b523a456
5 changed files with 103 additions and 55 deletions

View File

@ -82,6 +82,9 @@ class Ticket(models.Model):
platform = models.ForeignKey('Platform', on_delete=models.CASCADE)
user = models.ForeignKey(User, on_delete=models.CASCADE)
class Meta:
ordering = ['-time_update']
def get_absolute_url(self):
return reverse(
'ticket',

View File

@ -1,4 +1,5 @@
<header>
<section>
<nav class="navbar navbar-expand-lg bg-body-tertiary">
<div class="container">
<a class="navbar-brand" href="{% url 'index' %}">Logs Collector</a>
@ -22,7 +23,8 @@
role="button"
data-bs-toggle="dropdown"
aria-expanded="false"
>Tickets</a>
>Tickets</a
>
<ul class="dropdown-menu">
<li>
<a class="dropdown-item" href="{% url 'index' %}">All</a>
@ -32,7 +34,8 @@
<a
class="dropdown-item"
href="{{ platform.get_absolute_url }}"
>{{ platform.pretty_name}}</a>
>{{ platform.pretty_name}}</a
>
</li>
{% endfor %}
<li><hr class="dropdown-divider" /></li>
@ -55,4 +58,5 @@
</div>
</div>
</nav>
</section>
</header>

View File

@ -0,0 +1,37 @@
{% if page_obj.has_other_pages %}
<nav class="d-flex justify-content-center mt-3" aria-label="...">
<ul class="pagination">
{% if page_obj.has_previous %}
<li class="page-item">
<a
class="page-link"
href="?page={{ page_obj.previous_page_number }}"
>Back</a>
</li>
{% else %}
<li class="page-item disabled"><a class="page-link">Back</a></li>
{% endif %}
{% for page in paginator.page_range %}
{% if page_obj.number == page %}
<li class="page-item active" aria-current="page">
<button class="page-link">{{ page }}</button>
</li>
{% elif page >= page_obj.number|add:-2 and page <= page_obj.number|add:2%}
<li class="page-item">
<a class="page-link" href="?page={{ page }}">{{ page }}</a>
</li>
{% endif %}
{% endfor %}
{% if page_obj.has_next %}
<li class="page-item">
<a
class="page-link"
href="?page={{ page_obj.next_page_number }}"
>Next</a>
</li>
{% else %}
<li class="page-item disabled"><a class="page-link">Next</a></li>
{% endif %}
</ul>
</nav>
{% endif %}

View File

@ -91,7 +91,9 @@
</div>
</div>
{% endfor %}
{% include 'collector/pagination.html' %}
</div>
</section>
</main>
{% endblock content %}

View File

@ -21,6 +21,7 @@ class ListAllTickets(generic.ListView):
model = Ticket
template_name = 'collector/tickets.html'
context_object_name = 'tickets'
paginate_by = 5
def get_context_data(self, **kwargs):
context = super().get_context_data(**kwargs)
@ -33,6 +34,7 @@ class ListPlatformTickets(generic.ListView):
template_name = 'collector/tickets.html'
context_object_name = 'tickets'
allow_empty = False
paginate_by = 5
def get_queryset(self):
return Ticket.objects.filter(