@@ -8,15 +8,26 @@ class Meta:
8
8
model = Student
9
9
fields = ("id" ,"name" ,"branch" ,"year" ,"picture" ,"homeTown" ,"extraCurriculars" ,"socialMedia" , "linkedIn" ,"email" ,"parentId" ,"roll_no" )
10
10
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
12
23
13
24
class Query (graphene .ObjectType ):
14
25
students = graphene .List (StudentType )
15
26
children = graphene .List (StudentType , parent_id = graphene .String ())
16
27
student_path = graphene .List (StudentType , roll = graphene .String ())
17
28
student_sibling = graphene .List (StudentType , roll = graphene .String ())
18
29
student_search = graphene .List (StudentType , search_query = graphene .String ())
19
- student_batch = graphene .List (StudentType , roll = graphene .String ())
30
+ student_batch = graphene .List (graphene . List ( StudentType ) , roll = graphene .String ())
20
31
21
32
def resolve_students (root ,info ):
22
33
return Student .objects .all ()
@@ -30,7 +41,7 @@ def resolve_student_path(root, info, roll):
30
41
student = Student .objects .get (roll_no = roll )
31
42
pathObjects .append (student )
32
43
roll = student .parentId
33
- pathObjects .append (Student .objects .get (roll_no = roll ))
44
+ pathObjects .append (Student .objects .get (roll_no = roll ))
34
45
return pathObjects
35
46
36
47
def resolve_student_sibling (root ,info , roll ):
@@ -42,10 +53,11 @@ def resolve_student_batch(root,info,roll):
42
53
current_node = Student .objects .get (roll_no = roll )
43
54
year_of_node = current_node .year
44
55
current_batch = Student .objects .filter (year = year_of_node )
45
- tree_for_batch = []
46
- for person in current_batch :
47
- tree_for_batch .append (Query .resolve_student_path (root ,info ,person .roll_no ))
48
- return tree_for_batch
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 )
49
61
50
62
51
63
def resolve_student_search (root ,info , search_query ):
0 commit comments