AA
Size: a a a
AA
AA
views.py
class ContactView(generic.FormView):
"""Contact page & form."""
form_class = ContactForm
template_name = 'blog/contact.html'
success_url = reverse_lazy('blog:success')
def form_valid(self, form):
form.send_email()
return super(ContactView, self).form_valid(form)
AA
def post_detail(request, year, month, day, post):
post = get_object_or_404(Post, slug=post,
status='published',
publish__year=year,
publish__month=month,
publish__day=day)
# List of active comments for this post
comments = post.comments.filter(active=True)
if request.method == 'POST':
# A comment was posted
comment_form = CommentForm(data=request.POST)
if comment_form.is_valid():
# Create Comment object but don't save to database yet
new_comment = comment_form.save(commit=False)
# Assign the current post to the comment
new_comment.post = post
# Save the comment to the database
new_comment.save()
else:
comment_form = CommentForm()
# List of similar posts
post_tags_ids = post.tags.values_list('id', flat=True)
similar_posts = Post.published.filter(tags__in=post_tags_ids).exclude(id=post.id)
similar_posts = similar_posts.annotate(same_tags=Count('tags')).order_by('-same_tags',
'-publish')[:4]
return render(request, 'blog/post/detail.html', {'post': post,
'comments': comments,
'comment_form': comment_form,
'similar_posts': similar_posts})
AA
V
tn
tn
def post_detail(request, year, month, day, post):
post = get_object_or_404(Post, slug=post,
status='published',
publish__year=year,
publish__month=month,
publish__day=day)
# List of active comments for this post
comments = post.comments.filter(active=True)
if request.method == 'POST':
# A comment was posted
comment_form = CommentForm(data=request.POST)
if comment_form.is_valid():
# Create Comment object but don't save to database yet
new_comment = comment_form.save(commit=False)
# Assign the current post to the comment
new_comment.post = post
# Save the comment to the database
new_comment.save()
else:
comment_form = CommentForm()
# List of similar posts
post_tags_ids = post.tags.values_list('id', flat=True)
similar_posts = Post.published.filter(tags__in=post_tags_ids).exclude(id=post.id)
similar_posts = similar_posts.annotate(same_tags=Count('tags')).order_by('-same_tags',
'-publish')[:4]
return render(request, 'blog/post/detail.html', {'post': post,
'comments': comments,
'comment_form': comment_form,
'similar_posts': similar_posts})
AA
AA
tn
AA
RN
А
А
В
RN
В
НК
RN
А