Skip to content

Commit adfcdf3

Browse files
committed
added a resolver for fetching path of a node
1 parent 98c2c0b commit adfcdf3

File tree

3 files changed

+22
-7
lines changed

3 files changed

+22
-7
lines changed

backend/family_tree/student/admin.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
from django.contrib import admin
2+
#from student.models import Student
23

34
from .models import Student
45

5-
admin.site.register(Student)
6+
class StudentAdmin(admin.ModelAdmin):
7+
save_as=True
8+
9+
admin.site.register(Student, StudentAdmin)

backend/family_tree/student/models.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
from django.db import models
22

3+
class SocialMedia(models.Model):
4+
facebook = models.URLField(max_length=255)
5+
instagram = models.URLField(max_length=255)
6+
37
class Student(models.Model):
48
roll_no= models.CharField(max_length=9)
59
name= models.CharField(max_length=50)
@@ -8,15 +12,11 @@ class Student(models.Model):
812
picture= models.URLField(max_length=200)
913
homeTown= models.CharField(max_length=200)
1014
extraCurriculars= models.CharField(max_length=400)
11-
socialMedia= models.ForeignKey('SocialMedia', on_delete=models.CASCADE, default=None)
15+
socialMedia= models.ForeignKey(SocialMedia, on_delete=models.CASCADE, default=None, blank=True, null=True)
1216
linkedIn= models.URLField(max_length=200)
1317
email= models.EmailField(max_length=254)
1418
parentId= models.CharField(max_length=400)
1519

16-
17-
class SocialMedia(models.Model):
18-
facebook = models.URLField(max_length=255)
19-
instagram = models.URLField(max_length=255)
2020

2121

2222

backend/family_tree/student/schema.py

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,21 @@ class Meta:
88
fields= ("id","name","branch","year","picture","homeTown","extraCurriculars","socialMedia", "linkedIn","email","parentId","roll_no")
99
filter_fields=["id","name","branch","year","email","parentId","roll_no"]
1010

11+
1112
class Query(graphene.ObjectType):
1213
students=graphene.List(StudentType)
13-
14+
student_path= graphene.List(StudentType, roll=graphene.String())
1415
def resolve_students(root,info):
1516
return Student.objects.all()
17+
def resolve_student_path(root, info, roll):
18+
pathObjects=[]
19+
while(Student.objects.filter(roll_no=roll)[0].parentId!="root"):
20+
pathObjects.append(Student.objects.filter(roll_no=roll)[0])
21+
roll= Student.objects.filter(roll_no=roll)[0].parentId
22+
pathObjects.append(Student.objects.filter(roll_no=roll)[0])
23+
return pathObjects
24+
25+
26+
1627

1728
schema=graphene.Schema(query=Query)

0 commit comments

Comments
 (0)