【django】多对多表添加
发布时间:2020-12-15 17:09:07 所属栏目:大数据 来源:网络整理
导读: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 " )) s
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) ? (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |