Introduce pagination
This commit is contained in:
parent
6ccb68d28e
commit
e812a7a4c6
7 changed files with 122 additions and 3 deletions
1
static/bootstrap
Symbolic link
1
static/bootstrap
Symbolic link
|
@ -0,0 +1 @@
|
||||||
|
bootstrap-4.4.1-dist
|
|
@ -1,5 +1,7 @@
|
||||||
from django.contrib import admin
|
from django.contrib import admin
|
||||||
from django.contrib.auth.admin import UserAdmin
|
from django.contrib.auth.admin import UserAdmin
|
||||||
from .models import User
|
|
||||||
|
from .models import *
|
||||||
|
|
||||||
admin.site.register(User, UserAdmin)
|
admin.site.register(User, UserAdmin)
|
||||||
|
admin.site.register(BookmarkModel)
|
||||||
|
|
20
ubookmark/migrations/0003_bookmarkmodel_posted_at.py
Normal file
20
ubookmark/migrations/0003_bookmarkmodel_posted_at.py
Normal file
|
@ -0,0 +1,20 @@
|
||||||
|
# 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)
|
url = models.URLField(primary_key=True)
|
||||||
comment = models.CharField(max_length=2048)
|
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_BIND_PASSWORD = ""
|
||||||
AUTH_LDAP_USER_SEARCH = ""
|
AUTH_LDAP_USER_SEARCH = ""
|
||||||
|
|
||||||
|
SITE_NAME = "an unconfigured site"
|
||||||
|
|
||||||
|
|
||||||
# Password validation
|
# Password validation
|
||||||
|
|
|
@ -1 +1,82 @@
|
||||||
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>
|
||||||
|
|
|
@ -1,8 +1,17 @@
|
||||||
from django.views.generic.list import ListView
|
from django.views.generic.list import ListView
|
||||||
|
from django.conf import settings
|
||||||
|
|
||||||
from ubookmark.models import *
|
from ubookmark.models import *
|
||||||
|
|
||||||
class IndexView(ListView):
|
class IndexView(ListView):
|
||||||
|
|
||||||
model = BookmarkModel
|
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
|
||||||
|
|
Loading…
Reference in a new issue