We are loading on the web browser the content of the model "Post", which is ordered by "helium" (our variable for popularity).
Now, we'd like to order the same content by "pop_date" (our variable for due_date) when the user clicks on a button.
Is it possible to do it instantly without reloading the browser page?
The options we've seen until now:
- change the "order_by" and request a new list ( new operation on the database, reuploading all the medias again)
- use python "sorted" function (memory issues for many posts loaded)
models.py
class Post(models.Model):
pub_date = models.DateTimeField('date published',auto_now=True)
pop_date = models.DateTimeField('Popping time', blank=False)
helium=models.IntegerField(default=0)
(...)
views.py (query)
Post.objects.filter(pop_date__gte=timezone.now()).order_by(self.ordering,'-id')
url.py
# Order by Helium
url(r'^(?P<slug>[-\w]+)/popular$', views.IndexView.as_view(ordering='-helium'), name='index'),
# Order by Popping time
url(r'^(?P<slug>[-\w]+)/timeline$', views.IndexView.as_view(ordering='pop_date'), name='index_now'),