I want to group the model object according to the foreign key with a query or without any iteration.
example: Let, I have a model student
:
class Student(models.Model):
id=models.AutoField(primary_key=True)
parentId=models.ForeignKey(parent)
name=models.CharField()
age=models.IntegerField()
Here I want to create the group the student object
with respect to the parentId
using a query or any optimized way.