Skip to content

Commit 1eeed7a

Browse files
authored
Merge pull request #64 from akshatjain1004/main
Creates a Resolver to Fetch Batch
2 parents e1788f2 + 3c0a29f commit 1eeed7a

File tree

1 file changed

+24
-1
lines changed

1 file changed

+24
-1
lines changed

backend/family_tree/student/schema.py

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,26 @@ class Meta:
88
model= Student
99
fields= ("id","name","branch","year","picture","homeTown","extraCurriculars","socialMedia", "linkedIn","email","parentId","roll_no")
1010
filter_fields=["id","name","branch","year","email","parentId","roll_no"]
11-
11+
def tree_for_batch(root,info,batch):
12+
tree_for_batch=[]
13+
for student in batch:
14+
roll= student.roll_no
15+
pathObjects=[]
16+
while(Student.objects.get(roll_no=roll).parentId!="root"):
17+
student=Student.objects.get(roll_no=roll)
18+
pathObjects.append(student)
19+
roll= student.parentId
20+
pathObjects.append(Student.objects.get(roll_no=roll))
21+
tree_for_batch.append(pathObjects)
22+
return tree_for_batch
1223

1324
class Query(graphene.ObjectType):
1425
students=graphene.List(StudentType)
1526
children=graphene.List(StudentType, parent_id=graphene.String())
1627
student_path= graphene.List(StudentType, roll=graphene.String())
1728
student_sibling= graphene.List(StudentType, roll=graphene.String())
1829
student_search= graphene.List(StudentType, search_query=graphene.String())
30+
student_batch= graphene.List(graphene.List(StudentType), roll=graphene.String())
1931

2032
def resolve_students(root,info):
2133
return Student.objects.all()
@@ -37,6 +49,17 @@ def resolve_student_sibling(root,info, roll):
3749
return Student.objects.filter(parentId=student.parentId).exclude(roll_no=roll)
3850

3951

52+
def resolve_student_batch(root,info,roll):
53+
current_node= Student.objects.get(roll_no=roll)
54+
year_of_node= current_node.year
55+
current_batch= Student.objects.filter(year=year_of_node)
56+
# tree_for_batch=[]
57+
# for person in current_batch:
58+
# tree_for_batch.append(Query.resolve_student_path(root,info,person.roll_no))
59+
# return tree_for_batch
60+
return tree_for_batch(root,info,current_batch)
61+
62+
4063
def resolve_student_search(root,info, search_query):
4164
return Student.objects.filter(Q(name__icontains=search_query) | Q(roll_no__icontains= search_query))[0:8]
4265

0 commit comments

Comments
 (0)