mirror of
https://github.com/ae-utbm/sith.git
synced 2024-11-26 02:54:20 +00:00
forum: implement order by date for search
This commit is contained in:
parent
721b22a1e9
commit
6891174935
@ -107,6 +107,7 @@ class BigCharFieldIndex(indexes.CharField):
|
|||||||
class ForumMessageIndex(indexes.SearchIndex, indexes.Indexable):
|
class ForumMessageIndex(indexes.SearchIndex, indexes.Indexable):
|
||||||
text = BigCharFieldIndex(document=True, use_template=True)
|
text = BigCharFieldIndex(document=True, use_template=True)
|
||||||
auto = indexes.EdgeNgramField(use_template=True)
|
auto = indexes.EdgeNgramField(use_template=True)
|
||||||
|
date = indexes.DateTimeField(model_attr="date")
|
||||||
|
|
||||||
def get_model(self):
|
def get_model(self):
|
||||||
return ForumMessage
|
return ForumMessage
|
||||||
|
@ -54,11 +54,17 @@ class ForumSearchView(ListView):
|
|||||||
|
|
||||||
def get_queryset(self):
|
def get_queryset(self):
|
||||||
query = self.request.GET.get("query", "")
|
query = self.request.GET.get("query", "")
|
||||||
|
order_by = self.request.GET.get("order", "")
|
||||||
|
|
||||||
if query == "":
|
if query == "":
|
||||||
return []
|
return []
|
||||||
queryset = (
|
|
||||||
SearchQuerySet().models(ForumMessage).autocomplete(auto=query).load_all()
|
queryset = SearchQuerySet().models(ForumMessage).autocomplete(auto=query)
|
||||||
)
|
|
||||||
|
if order_by == "date":
|
||||||
|
queryset.order_by("date")
|
||||||
|
|
||||||
|
queryset = queryset.load_all()
|
||||||
|
|
||||||
# Filter unauthorized responses
|
# Filter unauthorized responses
|
||||||
resp = []
|
resp = []
|
||||||
|
Loading…
Reference in New Issue
Block a user