Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added tagging for blog posts, and read time for blog posts #10

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions blog/models.py
Original file line number Diff line number Diff line change
@@ -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"))
Expand All @@ -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"]
Expand All @@ -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")
Expand Down
3 changes: 2 additions & 1 deletion mysite/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
'blog',
'crispy_forms',
'django_summernote',
'taggit',
]

INSTALLED_APPS += ( 'django.contrib.sitemaps',)
Expand Down Expand Up @@ -134,7 +135,7 @@




TAGGIT_CASE_INSENSITIVE = True



Expand Down
1 change: 0 additions & 1 deletion requirments.txt
Original file line number Diff line number Diff line change
@@ -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
18 changes: 11 additions & 7 deletions templates/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -23,25 +23,29 @@ <h3 class=" site-heading my-4 mt-3 text-white"> Welcome to my awesome Blog </h3>
<div class="row">

<!-- Blog Entries Column -->
<div class="col-md-8 mt-3 left">
<div class="col-sm-12 col-md-8 mt-3">
{% for post in post_list %}
<div class="card mb-4">
<div class="card-body">
<h2 class="card-title">{{ post.title }}</h2>
<p class="card-text text-muted h6">{{ post.author }} | {{ post.created_on}} </p>

<p class="card-text">{{post.content|slice:":200" }}</p>
<p class="card-text text-muted h6">{{ post.author }} | {{ post.created_on}} | {{ post.get_read_time }} </p>
<p>
{% for tag in post.tags.all %}
<span class="badge badge-primary">{{ tag }}</span>
{% endfor %}
</p>
<p class="card-text">{{post.content|safe|slice:":200" }}</p>
<a href="{% url 'post_detail' post.slug %}" class="btn btn-primary">Read More &rarr;</a>
</div>

</div>
{% endfor %}

</div>
{% block sidebar %}
{% include 'sidebar.html' %}
{% endblock sidebar %}
</div>
{% block sidebar %}
{% include 'sidebar.html' %}
{% endblock sidebar %}
</div>
{% if is_paginated %}
<nav aria-label="Page navigation conatiner"></nav>
Expand Down
7 changes: 6 additions & 1 deletion templates/post_detail.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,12 @@
<div class="col-md-8 card mb-4 mt-3 left top">
<div class="card-body">
<h1>{% block title %} {{ post.title }} {% endblock title %}</h1>
<p class=" text-muted">{{ post.author }} | {{ post.created_on }}</p>
<p class=" text-muted">{{ post.author }} | {{ post.created_on }} | {{ post.get_read_time }}</p>
<p>
{% for tag in post.tags.all %}
<span class="badge badge-primary">{{ tag }}</span>
{% endfor %}
</p>
<p class="card-text ">{{ post.content | safe }}</p>
</div>
</div>
Expand Down
2 changes: 1 addition & 1 deletion templates/sidebar.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@


<!-- Sidebar Widgets Column -->
<div class="col-md-4 float-right ">
<div class="col-sm-12 col-md-4">
<div class="card my-4">
<h5 class="card-header">About Us</h5>
<div class="card-body">
Expand Down