最後の POST/PUt/DELETE またはデータベース内のあらゆる種類のトランザクションを元に戻したいです。Django-reversionについて読み、実装してみました。しかし、運が悪かった。これが私のコードです。私が何をしているのか確認してください!!!
反転するモデル:-
@reversion.register
class Shipment(models.Model):
job_id = models.CharField(max_length = 255)
time = models.DateTimeField( auto_now_add = True, db_index = True)
@reversion.register
class ShipmentScanMapping(models.Model):
arm_id = models.CharField(max_length = 255)
status = models.CharField(max_length = 255)
barcode = models.CharField(max_length = 255)
reference_number = models.CharField(max_length = 255)
customer_name = models.CharField(max_length = 255)
shipment = models.ForeignKey('Shipment',related_name ='scans')
time = models.DateTimeField( auto_now_add = True)
ビュー
@csrf_exempt
@reversion.create_revision()
def db_commit(request):
arm_id = scan_status = barcode = reference_number = customer_name = job_id = 12
if request.is_ajax():
shipment_obj = Shipment(job_id = job_id)
shipment_obj.save()
ShipmentScanMapping.objects.create(arm_id = arm_id,status = scan_status,barcode = barcode,reference_number = reference_number,
customer_name = customer_name ,shipment= shipment_obj)
return HttpResponse(json.dumps('Success'), content_type = "application/json")
@csrf_exempt
def db_undo(request):
job_id = 12 # just for demo purpose
shipment_obj = Shipment.objects.filter(job_id = job_id).order_by('-time')[0]
your_model = ShipmentScanMapping.objects.get(shipment = shipment_obj)
version_list = reversion.get_unique_for_object(your_model)[0]
#version_data = version_list.field_dict
#print version_data
version_list.revert()
return HttpResponse(json.dumps('Success'), content_type = "application/json")
私は何を間違っていますか??