@@ -8,14 +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 , parentId = 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 ())
30
+ student_batch = graphene .List (graphene .List (StudentType ), roll = graphene .String ())
19
31
20
32
def resolve_students (root ,info ):
21
33
return Student .objects .all ()
@@ -37,6 +49,17 @@ def resolve_student_sibling(root,info, roll):
37
49
return Student .objects .filter (parentId = student .parentId ).exclude (roll_no = roll )
38
50
39
51
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
+
40
63
def resolve_student_search (root ,info , search_query ):
41
64
return Student .objects .filter (Q (name__icontains = search_query ) | Q (roll_no__icontains = search_query ))[0 :8 ]
42
65
0 commit comments