【django】多对多表添加

【django】多对多表添加,第1张

概述from rest_framework.views import APIView from django.shortcuts import render,redirect,HttpResponse f
from rest_framework.vIEws import APIVIEwfrom django.shortcuts  render,redirect,httpResponsefrom dal  modelsfrom django.http  JsonResponseclass 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)

 

总结

以上是内存溢出为你收集整理的【django】多对多表添加全部内容,希望文章能够帮你解决【django】多对多表添加所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/langs/1222814.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-06-05
下一篇 2022-06-05

发表评论

登录后才能评论

评论列表(0条)

保存