• 【django】多对多表添加


    from rest_framework.views import APIView
    from django.shortcuts import render,redirect,HttpResponse
    from dal import models
    from django.http import 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['code'] = 444
                message['message'] = "添加失败"
                return JsonResponse(message)
  • 相关阅读:
    鼠标和滚轮事件
    UI事件
    跨浏览器的事件对象
    DOM中的事件对象和IE事件对象
    Monolog手册参考
    nginx 配置
    es elasticsearch-head安装
    es ik分词插件安装
    yii2.0+es
    php分词工具scws
  • 原文地址:https://www.cnblogs.com/wanghong1994/p/12324926.html
Copyright © 2020-2023  润新知