'Django queryset by first letter?
For example my name is David and my friend is Daniel. I want to show these two names in their first letter wise .
Item has a 'name' field. In the template I want to show:
A Axes Alcohol
B Bazookas
C Coins Cartridges
S Swords Sparrows
just like these picture.
views.py
enter code here
def client(request):
clients = Appointment.objects.filter(practitioner__user=request.user).order_by('-time')
context = {'clients': clients}
return render(request, 'practitioner/clients.html', context)
template code is
enter code here
<div class="listing-wrapeer">
{% for client in clients %}
<h3>{{client.user.username.0}}</h3>
<ul>
<li>
<div class="round-div">
<img src="" alt="">
</div>
<div class="alphabetic-details">
<span class="name">{{client.user.username}}</span>
<span>Next appointment: 2nd of July @ 19:20</span>
</div>
</li>
{% endfor %}
</ul>
</div>
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|