class Comment(models.Model):
class Meta:
db_table = 'comments'
comment_text = models.TextField(max_length=200, verbose_name='Добавить комментарий')
comment_created_at = models.DateTimeField(null=True, auto_now=True, verbose_name='Создан')
comment_product = models.ForeignKey(Product)
def product(request, product_slug=None):
comment_form = CommentForm
args = {}
args.update(csrf(request))
args['product'] = Product.objects.get(product_slug=product_slug)
args['comments'] = Comment.objects.filter(comment_product_id=product_slug)
args['username'] = request.user.username
args['form'] = comment_form
return render_to_response("product.html", args)
{% if comments %}
<div class="row comment-row">
{% for comment in comments %}
<div class="col-md-12">
<p>{{ comment.comment_created_at|date:"SHORT_DATETIME_FORMAT" }}</p>
<blockquote class="comment">
<p>{{ comment.comment_text }}</p>
</blockquote>
</div>
{% endfor %}
</div>
{% endif %}
args['comments'] = Comment.objects.filter(comment_product_id=product_slug)
date_from = datetime.datetime.now() - datetime.timedelta(days=1)
args['comments'] = Comment.objects.filter(comment_product_id=product_slug, comment_created_at__gte=date_from).order_by('comment_created_at')
import datetime