How to display comments sorted by date added?

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

    model

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

  • 1 Answers
  • 0
    Change 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 to import datetime

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

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