From: Patrick Canterino Date: Fri, 28 Jan 2022 19:50:09 +0000 (+0100) Subject: When an admin is logged on, display drafts X-Git-Url: https://git.p6c8.net/pcdenotes.git/commitdiff_plain/d063502baa4a57159666cf9386aa1809f29fff22 When an admin is logged on, display drafts --- diff --git a/notes/models.py b/notes/models.py index e480221..ed86192 100644 --- a/notes/models.py +++ b/notes/models.py @@ -27,3 +27,8 @@ class Note(models.Model): return reverse("notes:note_detail", kwargs={"note_slug": self.slug}) #return "/notes/%s" % (self.slug) + def is_draft(self): + return self.status == 0 + + def is_published(self): + return self.status == 1 diff --git a/notes/templates/note.html b/notes/templates/note.html index 0dbba54..1bce423 100644 --- a/notes/templates/note.html +++ b/notes/templates/note.html @@ -1,6 +1,7 @@ {% load markdownify %} -
-

{{ note.title }}

+
+

{{ note.title }}

+ {% if note.is_draft %}

Status: Draft

{% endif %}
{{ note.content|linebreaksbr|markdownify }}

Published on {{ note.created_at|date:"Y-m-d, H:i" }}

\ No newline at end of file diff --git a/notes/views.py b/notes/views.py index 793f9ed..f41a99d 100644 --- a/notes/views.py +++ b/notes/views.py @@ -7,7 +7,8 @@ from .models import Note # Create your views here. def note_list(request): - notes = Note.objects.filter(status=1) + notes = Note.objects.all() if request.user.is_staff else Note.objects.filter(status=1) + notes_count = Note.objects.filter(status=1).count() paginator = Paginator(notes, NOTES_PER_PAGE) @@ -25,5 +26,5 @@ def note_list(request): return render(request, 'note_list.html', {'notes_page': notes_page, 'notes_count': notes_count, 'pages': paginator, 'page_number': page_number, 'page_count': page_count}) def note_detail(request, note_slug): - note = get_object_or_404(Note, slug=note_slug, status=1) + note = get_object_or_404(Note, slug=note_slug) if request.user.is_staff else get_object_or_404(Note, slug=note_slug, status=1) return render(request, 'note_detail.html', {'note': note}) \ No newline at end of file