I’m trying to copy an object and it’s children from. The parent object copies just fine, as does one of the children. The remaining don’t do anything. I don’t get an output in the terminal, and there is no change to the database.
def copy_workorder_item(request, pk, workorder=None):
#Copy line item to current workorder
if workorder:
print(pk)
obj = WorkorderItem.objects.get(pk=pk)
obj.pk = None
obj.save()
try:
objdetail = KruegerJobDetail.objects.get(workorder_item=pk)
objdetail.pk = None
objdetail.workorder_item = obj.pk
objdetail.last_item_order = obj.workorder_hr
objdetail.last_item_price = objdetail.price_total
objdetail.save()
except:
pass
try:
objdetail = OrderOut.objects.get(workorder_item=pk)
objdetail.pk = None
objdetail.workorder_item = obj.pk
objdetail.last_item_order = obj.workorder_hr
objdetail.last_item_price = objdetail.price_total
objdetail.save()
except:
pass
try:
objdetail = SetPrice.objects.get(workorder_item=pk)
objdetail.pk = None
objdetail.workorder_item = obj.pk
#objdetail.last_item_order = obj.workorder_hr
#objdetail.last_item_price = objdetail.price_total
objdetail.save()
except:
return HttpResponse(status=204, headers={'HX-Trigger': 'itemListChanged'})
The workorder and the KruegerJobDetail both copy as expected. the Orderout and SetPrice go through the try blocks, but they don’t save at the end. Is there a way to get errors from the .save?