ManyToManyField 增加记录

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
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')

  

 

总结: 好麻烦.

posted @   CrossPython  阅读(546)  评论(0编辑  收藏  举报
点击右上角即可分享
微信分享提示