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
{% load markdownify %}
-<article class="container mt-5">
- <h2><a href="{{ note.get_absolute_url }}" class="link-dark">{{ note.title }}</a></h2>
+<article class="container mt-5{% if note.is_draft %} text-muted{% endif %}">
+ <h2><a href="{{ note.get_absolute_url }}" class="{% if note.is_draft %}text-muted{% else %}link-dark{% endif %}">{{ note.title }}</a></h2>
+ {% if note.is_draft %}<p class="fw-bold">Status: Draft</p>{% endif %}
<div class="mt-3">{{ note.content|linebreaksbr|markdownify }}</div>
<p class="fst-italic" style="font-size: smaller;">Published on {{ note.created_at|date:"Y-m-d, H:i" }}</p>
</article>
\ No newline at end of file
# 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)
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