我很难过,需要有关我的功能的帮助。我有两个表学生和学生信息。学生信息是该学生的所有监护人信息。我将此数据与主学生表分开,因此您可以根据需要将任意数量的监护人添加到具有新记录的学生文件中。我得到的错误如下。
无法分配“'1'”:“StudentInformation.studentpsid”必须是“Student”实例。
附件你会看到我的代码。学生信息中的studentpsid是student的外键。
def ImportStudentGuardian(request):
AuthTokenP(request)
print("Getting student guardian data from SIS for K-8")
#Pulls K-8 Guardians
url = "removed for posting"
payload = {}
token = APIInformation.objects.get(api_name="PowerSchool")
key = token.key
headers = {'Authorization': 'Bearer {}'.format(key)}
response = requests.request("GET", url, headers=headers, data = payload)
encode_xml = response.text.encode('utf8')
xml_string = ET.fromstring(encode_xml)
students = xml_string.findall("student")
for student in students:
#XML Values
psid = student.find("id").text
try:
mother = student.find("contact").find("mother").text
except Exception:
mother = ""
try:
father = student.find("contact").find("father").text
except Exception:
father = ""
if Student.objects.filter(studentpsid=psid).exists():
print("Accessing guardian information.")
m = StudentInformation.objects.create(studentpsid=psid,guardian_name = mother, relation = "Mom") <---- Function Fails here
print("Record doesn't exist for mom, creating record.")
m.save()
d= StudentInformation.objects.create(studentpsid=psid,guardian_name = father, relation = "Dad")
print("Record doesn't exist for dad, creating record.")
d.save()
return ("Updated Guardian Information ")
交互式爱情
相关分类