How to display comments sorted by date added?

  • 0
    There is a model, a view and a template


    [[[ 0_0]]]
    Django Charles Dixon, May 6, 2019

  • 1 Answers
  • 0
    Change this line in
    args['comments'] = Comment.objects.filter(comment_product_id=product_slug)

    On these:
    date_from = - 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 to import datetime

    I typed the code right away in the browser without testing, so there may be errors

Your Answer
To place the code, please use CodePen or similar tool. Thanks you!