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')
总结: 好麻烦.