From: Frédéric Péters Date: Sun, 29 Dec 2019 17:23:20 +0000 (+0100) Subject: views: add page to list notes by tag X-Git-Tag: v2022~52 X-Git-Url: https://git.0d.be/?p=chloro.git;a=commitdiff_plain;h=80e13c7d63c7ac56be0c48ccb803a171db63167e views: add page to list notes by tag --- diff --git a/chloro/phyll/migrations/0002_auto_20191229_1932.py b/chloro/phyll/migrations/0002_auto_20191229_1932.py new file mode 100644 index 0000000..5650df4 --- /dev/null +++ b/chloro/phyll/migrations/0002_auto_20191229_1932.py @@ -0,0 +1,16 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.11.17 on 2019-12-29 18:32 +from __future__ import unicode_literals + +from django.db import migrations + + +class Migration(migrations.Migration): + + dependencies = [ + ('phyll', '0001_initial'), + ] + + operations = [ + migrations.AlterModelOptions(name='note', options={'ordering': ['-creation_timestamp']},), + ] diff --git a/chloro/phyll/models.py b/chloro/phyll/models.py index b8872c4..2307389 100644 --- a/chloro/phyll/models.py +++ b/chloro/phyll/models.py @@ -29,5 +29,8 @@ class Note(models.Model): creation_timestamp = models.DateTimeField(auto_now_add=True) last_update_timestamp = models.DateTimeField(auto_now=True) + class Meta: + ordering = ['-creation_timestamp'] + def get_absolute_url(self): return '/%s/' % self.slug diff --git a/chloro/phyll/templates/phyll/note_list.html b/chloro/phyll/templates/phyll/note_list.html new file mode 100644 index 0000000..abc30a0 --- /dev/null +++ b/chloro/phyll/templates/phyll/note_list.html @@ -0,0 +1,20 @@ +{% extends "phyll/base.html" %} +{% load i18n %} + +{% block content-class %}post-list{% endblock %} + +{% block body %} +
+

{{ view.kwargs.tag }}

+ +
+{% endblock %} + +{% block bottom-actions %} +{% trans "Edit" %} +{% trans "Delete" %} +{% endblock %} diff --git a/chloro/phyll/urls.py b/chloro/phyll/urls.py index 1418810..13c70ba 100644 --- a/chloro/phyll/urls.py +++ b/chloro/phyll/urls.py @@ -39,6 +39,7 @@ urlpatterns = [ staff_member_required(views.NoteDeleteView.as_view(), login_url='login'), ), url(r'^new-note/$', staff_member_required(views.NoteAddView.as_view(), login_url='login')), + url(r'^tag/(?P[\w:-]+)/$', views.ListOnTagView.as_view()), url(r'^(?P\d{4})/(?P\d{2})/(?P\d{2})/(?P[\w:-]+)/$', views.NoteView.as_view()), url(r'^(?P[\w:-]+)/$', views.NoteView.as_view()), url(r'^$', views.HomeView.as_view()), diff --git a/chloro/phyll/views.py b/chloro/phyll/views.py index 5387b70..f645f39 100644 --- a/chloro/phyll/views.py +++ b/chloro/phyll/views.py @@ -15,7 +15,7 @@ # along with this program. If not, see . from django.http import Http404 -from django.views.generic import CreateView, DeleteView, DetailView, UpdateView, TemplateView +from django.views.generic import CreateView, DeleteView, DetailView, ListView, UpdateView, TemplateView from .models import Note @@ -56,3 +56,10 @@ class NoteDeleteView(DeleteView): class HomeView(TemplateView): template_name = 'phyll/home.html' + + +class ListOnTagView(ListView): + model = Note + + def get_queryset(self): + return Note.objects.filter(tags__name__in=[self.kwargs['tag']])