0

If I want to query all users of the whole alphabet could I do this in a view or do I run into a lot of performance issues?

users_a = User.objects.filter(username__startswith="a")
users_b = User.objects.filter(username__startswith="b")
users_c = User.objects.filter(username__startswith="c")
users_d = User.objects.filter(username__startswith="d")
users_e = User.objects.filter(username__startswith="e")

To clarify what I want to achieve:

My view:

def site_list(request):
    from django.contrib.auth.models import User
    users_a = User.objects.filter(username__startswith="a")
    return render(request, 'lists/sites.html', {'users_a': users_a})

My template:

<div class="col-md-12">
<h3>A</h3></div>
{% for user in users_a %}
  <div class="col-md-3">
    <a href="{% if request.is_secure %}https{% else %}http{% endif %}://{{ user.username }}.{{ request.get_host }}">
      <img class="avatar" src="{% avatar_url user 60 %}" alt="#">
      <span class="title">{{ user.first_name }} {{ user.last_name }}</span>
      <span class="url">{{ user.username }}.domain.com</span>
    </a>
  </div>
{% endfor %}
Droadpc
  • 79
  • 7

0 Answers0