diff --git a/blog/models.py b/blog/models.py index d45847d..05cb93c 100755 --- a/blog/models.py +++ b/blog/models.py @@ -1,5 +1,8 @@ +import readtime + from django.db import models from django.contrib.auth.models import User +from taggit.managers import TaggableManager STATUS = ((0, "Draft"), (1, "Publish")) @@ -15,6 +18,7 @@ class Post(models.Model): content = models.TextField() created_on = models.DateTimeField(auto_now_add=True) status = models.IntegerField(choices=STATUS, default=0) + tags = TaggableManager() class Meta: ordering = ["-created_on"] @@ -27,6 +31,12 @@ def get_absolute_url(self): return reverse("post_detail", kwargs={"slug": str(self.slug)}) + def get_read_time(self): + ''' Returns the read time of the WYSIWYG content field. ''' + string = str(self.content) + result = readtime.of_html(string, wpm=200) + return result + class Comment(models.Model): post = models.ForeignKey(Post, on_delete=models.CASCADE, related_name="comments") diff --git a/mysite/settings.py b/mysite/settings.py index 0317a9e..4cda249 100755 --- a/mysite/settings.py +++ b/mysite/settings.py @@ -42,6 +42,7 @@ 'blog', 'crispy_forms', 'django_summernote', + 'taggit', ] INSTALLED_APPS += ( 'django.contrib.sitemaps',) @@ -134,7 +135,7 @@ - +TAGGIT_CASE_INSENSITIVE = True diff --git a/requirments.txt b/requirments.txt index 127268f..3ea578c 100755 --- a/requirments.txt +++ b/requirments.txt @@ -1,6 +1,5 @@ Django==2.2.8 django-crispy-forms==1.8.1 django-summernote==0.8.11.4 -pkg-resources==0.0.0 pytz==2019.3 sqlparse==0.3.0 diff --git a/templates/index.html b/templates/index.html index c17c464..8d16c9f 100755 --- a/templates/index.html +++ b/templates/index.html @@ -23,14 +23,18 @@

Welcome to my awesome Blog

-
+
{% for post in post_list %}

{{ post.title }}

-

{{ post.author }} | {{ post.created_on}}

- -

{{post.content|slice:":200" }}

+

{{ post.author }} | {{ post.created_on}} | {{ post.get_read_time }}

+

+ {% for tag in post.tags.all %} + {{ tag }} + {% endfor %} +

+

{{post.content|safe|slice:":200" }}

Read More →
@@ -38,10 +42,10 @@

{{ post.title }}

{% endfor %}
- {% block sidebar %} - {% include 'sidebar.html' %} - {% endblock sidebar %}
+ {% block sidebar %} + {% include 'sidebar.html' %} + {% endblock sidebar %}
{% if is_paginated %} diff --git a/templates/post_detail.html b/templates/post_detail.html index 658691a..0f215f9 100755 --- a/templates/post_detail.html +++ b/templates/post_detail.html @@ -6,7 +6,12 @@

{% block title %} {{ post.title }} {% endblock title %}

-

{{ post.author }} | {{ post.created_on }}

+

{{ post.author }} | {{ post.created_on }} | {{ post.get_read_time }}

+

+ {% for tag in post.tags.all %} + {{ tag }} + {% endfor %} +

{{ post.content | safe }}

diff --git a/templates/sidebar.html b/templates/sidebar.html index 0ed1607..af002a5 100755 --- a/templates/sidebar.html +++ b/templates/sidebar.html @@ -3,7 +3,7 @@ -
+
About Us