Answer the question
In order to leave comments, you need to log in
How in Django to get in the finished results, along with the main query from the table, additional information from another table?
The point is. I have clients. These are the users of the User model that are added to the clients group. To get them all and then display them in the template, there is such a view in views.py:
def clients_all_view(request):
group = Group.objects.get(name='clients')
list_clients = group.user_set.all().order_by('-id')
context = {
'title': 'Список всех клиентов',
'personal': True,
'clients': list_clients,
}
return render(request, 'personal/clients.html', context=context)
class Order(models.Model):
user = models.ForeignKey(settings.AUTH_USER_MODEL, on_delete=models.CASCADE, )
...
list_clients = group.user_set.all().order_by('-id')
something to add so that there is an additional call to the Orders model and the number of orders of each found user is selected from the database of this model, supplementing the total data of the entire list_clients list?
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question