class Post(models.Model):
title = models.CharField(max_length=200)
text = models.TextField()
date_pub = models.DateField('date_pub')
tags = TaggableManager()
def __str__(self):
return "{0}".format(self.id)
def post(request, index):
try:
page_post = Post.objects.get(id=index)
previous_id = page_post.id - 1
next_id = page_post.id + 1
tag = page_post.tags
context = {
'page_post': page_post,
'previous_id': previous_id,
'next_id': next_id,
'max_id': len(Post.objects.all()),
'tag': tag,
}
return render(request, "post.html", context)
except Post.DoesNotExist:
return render(request, "error_page.html")
<div class="container" style="margin-top: 100px;">
<div class="row">
<div class="col-xs-0 col-md-3"></div>
<div class="col-xs-0 col-md-6">
{% for post in posts %}
<div class="post-block">
<div class="container-fluid">
<div class="row">
<div class="col-xs-12">
<h3>{{ post.title|truncatechars_html:30 }}</h3>
<h6>Теги: {{ post.tag }}</h6>
<h4 class="text-right">Дата: {{ post.date_pub }}</h4>
<hr>
</div>
</div>
</div>
<div class="row">
<div class="col-xs-12">
<div class="col-xs-11">
<p class="col_for_main">{{ post.text|truncatechars_html:100 }}</p>
</div>
</div>
</div>
<div class="row">
<div class="col-xs-12 text-right">
<div class="btn-group">
<a class="btn btn-sm btn-default" href="post/{{ post.id }}">Read</a>
<button class="btn btn-sm btn-default">Add to favorite</button>
</div>
</div>
</div>
</div>
<br>
{% endfor %}
</div>
<div class="col-xs-0 col-md-3"></div>
</div>
</div>