Commit e812a7a4 authored by Nico Schottelius's avatar Nico Schottelius

Introduce pagination

parent 6ccb68d2
bootstrap-4.4.1-dist
\ No newline at end of file
from django.contrib import admin
from django.contrib.auth.admin import UserAdmin
from .models import User
from .models import *
admin.site.register(User, UserAdmin)
admin.site.register(BookmarkModel)
# Generated by Django 3.0.5 on 2020-04-25 15:57
from django.db import migrations, models
import django.utils.timezone
class Migration(migrations.Migration):
dependencies = [
('ubookmark', '0002_bookmarkmodel'),
]
operations = [
migrations.AddField(
model_name='bookmarkmodel',
name='posted_at',
field=models.DateTimeField(auto_now_add=True, default=django.utils.timezone.now),
preserve_default=False,
),
]
......@@ -14,3 +14,8 @@ class BookmarkModel(models.Model):
url = models.URLField(primary_key=True)
comment = models.CharField(max_length=2048)
posted_at = models.DateTimeField(auto_now_add=True)
def __str__(self):
return "{} posted by {}".format(self.url, self.owner)
......@@ -99,6 +99,7 @@ except (ModuleNotFoundError, ImportError):
AUTH_LDAP_BIND_PASSWORD = ""
AUTH_LDAP_USER_SEARCH = ""
SITE_NAME = "an unconfigured site"
# Password validation
......
Something in here!
{% load static %}
<!doctype html>
<html lang="en">
<head>
<!-- Required meta tags -->
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<!-- Bootstrap CSS -->
<link rel="stylesheet" href="{% static '/bootstrap/css/bootstrap.min.css' %}">
<title>{{ site_name }} powered by ubookmark</title>
</head>
<body>
<h1>{{ site_name }}</h1>
<div>
{% autoescape off %}
<p>{{ site_description }}</p>
{% endautoescape %}
</div>
<div>
<ul class="list-group">
{% for bookmark in object_list %}
<li class="list-group-item">
<a href="{{ bookmark.url }}">{{ bookmark.comment }}
({{ bookmark.url }}) </a>
<div class="text-muted">
(posted by {{ bookmark.owner }} on {{ bookmark.posted_at }})
</div>
</li>
{% endfor %}
</ul>
</div>
<nav aria-label="Page navigation example">
<ul class="pagination">
{% if page_obj.has_previous %}
<li class="page-item">
<a class="page-link" href="?page=1">first</a>
</li>
<li class="page-item">
<a class="page-link" href="?page={{ page_obj.previous_page_number }}">previous</a>
</li>
{% else %}
<li class="page-item disabled">
<a class="page-link" href="#">first</a>
</li>
<li class="page-item disabled">
<a class="page-link" href="#">previous</a>
</li>
{% endif %}
<li class="page-item disabled">
<a class="page-link" href="#">{{ page_obj.number }} / {{ page_obj.paginator.num_pages }}</a>
</li>
{% if page_obj.has_next %}
<li class="page-item">
<a class="page-link" href="?page={{ page_obj.next_page_number }}">next</a>
</li>
<li class="page-item">
<a class="page-link" href="?page={{ page_obj.paginator.num_pages }}">last</a>
</li>
{% else %}
<li class="page-item disabled">
<a class="page-link" href="#">next</a>
</li>
<li class="page-item disabled">
<a class="page-link" href="#">last</a>
</li>
{% endif %}
</nav>
<script src="{% static '/bootstrap/js/bootstrap.min.js' %}"</script>
</body>
</html>
from django.views.generic.list import ListView
from django.conf import settings
from ubookmark.models import *
class IndexView(ListView):
model = BookmarkModel
paginate_by = 50
paginate_by = 3
queryset = BookmarkModel.objects.order_by('-posted_at')
def get_context_data(self, **kwargs):
context = super(IndexView, self).get_context_data(**kwargs)
context['site_name'] = settings.SITE_NAME
context['site_description'] = settings.SITE_DESCRIPTION
return context
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment