If i have model like this
class User(models.Model):
name = models.CharField(max_length=255)
organization = models.ForeignKey(
"organization.Organization", on_delete=models.CASCADE
)
school = models.ForeignKey(
school, on_delete=models.CASCADE,)
And then I receive and input of list of lists of user ID. Like this:
list_of_lists_of_user_id = [ [11,21,23] , [12, 324] , [909,2,12,444,242] , ....... ]
I want to return the same kind of list but not with just ID, instead I want the other value like "name" and "school" too. So I want to return the list of queryset of User's name and School I would have to loop through like this:
return_list_of_query_set = []
for group in list_of_lists_of_user_id:
query_set = User.values("name","school").filter(
id__in=group
)
return_list_of_query_set.append(query_set)
How would I optimize this for loop and don't make 1000s queries