python - Paginated based on the alphabet (A-Z) -
I have a simple contact application where I want to paginate the contact list based on the first name alphabet.
Here's my idea
def contact (request): contact_list = contact.objects.filter (user = request.user) .order_by ('first_name') return render (Request, '
This is my template
& lt; ul & gt; Contact / contact html' {contact_list}: contact_list}) < {%} gt; for contact in / code> {Contact_list%}; & Lt; A href = "/ contacts / {{contact.id}} /" & gt; {{Contact.first_name}} & lt; / A & gt; & Lt; / Li & gt; {% Endfor%} & lt; / Ul & gt;
Is there a default way in Django that does this? Is there but I think that only divides data into pages, what would be the easiest way to do this?
It seems that a letter-based constructor is not present in the error. Such as page & lt; & Lt; & Lt; It shows a hand-made implementation.
However, this is not so difficult to apply: You can base yourself on the initial keyword and:
pages = [myQuerySet.filter ("ABC ... XYZ "] # full alphabet here
(my partnership is, in fact, contact list, my field actually, first_name).
Comments
Post a Comment