How to display comments sorted by date added?
-
There is a model, a view and a template
model
1 AnswersChange this line in views.py
args['comments'] = Comment.objects.filter(comment_product_id=product_slug)
On these:
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')
And don't forget toimport datetime
I typed the code right away in the browser without testing, so there may be errorsAnonymous
Your AnswerTo place the code, please use CodePen or similar tool. Thanks you!