zoukankan      html  css  js  c++  java
  • ManyToManyField 增加记录

    class BOMView(View):
    
        def get(self,request):
            obj=BOMForm()
            return render(request,'bom.html',{'obj':obj})
    
        def post(self,request):
            data={
                'father':'CC',
                'son':'DD',
                'usage':2.0
            }
            obj=BOMSheet.objects.create(usage=data['usage'])
            father_id=ItemSheet.objects.filter(item=data['father']).first().id
            son_id=ItemSheet.objects.filter(item=data['son']).first().id
            obj.father.add(father_id)
            obj.son.add(son_id)
            obj.save()
            return HttpResponse('ok')
    

      

    总结: 好麻烦.

  • 相关阅读:
    type和object详解
    元类+单例
    单表查询和多表查询
    外键
    存储引擎,MySQL中的数据类型及约束
    壹拾壹




  • 原文地址:https://www.cnblogs.com/pythonClub/p/9812824.html
Copyright © 2011-2022 走看看