Answer the question
In order to leave comments, you need to log in
How to sort fields?
I need to sort notes by creation date, by category, and so on. tell me how to do it right?
a method that simply displays all the notes looks like this
def index(request):
note = Note.objects.filter(user=request.user.id)
return render(request, 'note/index.html',
{
'note' : note,
}
)
Answer the question
In order to leave comments, you need to log in
Well, probably it would be necessary to add a date, a category to the model, and then read the Dzhanga doc and see how to do sorting in it.
Try Django-filter
Generic, reusable application to alleviate writing some of the more mundane bits of view code. Specifically, it allows users to filter down a queryset based on a model's fields, displaying the form to let them do this.
https://django-filter.readthedocs.org/en/latest/us...
It is possible to implement requests through GET, and in view through if / elif filtering or sorting branching:
def index(request):
if request.GET['pub_date']:
items = Note.objects.order_by('-pub_date')
else:
items = Note.objects.all()
return render(...)
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question