from rest_framework.views import APIView from django.shortcuts render,redirect,HttpResponse from dal models from django.http JsonResponse class AddSubject(APIView): def post(self,request): username = str(request.data.get("username")) subject_title_id = str(request.data.get(subject_title_id)) user_id = models.UserInfo.objects.get(username=username).pk # 学生ID subject_title_obj = models.Subject.objects.get(pk=subject_title_id) 课程ID message = {} try: 课程ID 多对多 添加对应字段的 学生ID subject_title_obj.subject_student.add(user_id) message['code'] = 200 message[message'] = 添加成功" return JsonResponse(message) except Exception as e: print(e) message['] = 444添加失败return JsonResponse(message)
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。