S
S
s_katala2018-06-05 10:09:12
Django
s_katala, 2018-06-05 10:09:12

How can I change the sorting of a list?

How to switch the sorting of a comment list?
comments.model

class Comment(models.Model):
  post = models.ForeignKey(Post, related_name='comments', on_delete=models.CASCADE)
  author = models.ForeignKey(settings.AUTH_USER_MODEL, on_delete=models.CASCADE,)
  content = models.TextField()
  date_add = models.DateTimeField(default=timezone.now)
  approved_comment = models.BooleanField(default=False)

  def approve(self):
    self.approved_comment = True
    self.save()

  def get_absolute_url(self):
    return reverse('post', kwargs={'pk': self.pk})

  def __str__(self):
    return self.content

<li class="active"><a href="#" data-type="1"><b>Старые</b></a></li>
<li class=""><a href="#" data-type="2"><b>Новые</b></a></li>
<li class=""><a href="#" data-type="3"><b>Популярные</b></a></li>

Answer the question

In order to leave comments, you need to log in

1 answer(s)
R
Roman Kitaev, 2018-06-05
@deliro

.order_by()

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question