def _check_current_version(self, instance):
"""
Check that the edited_version parameter matches the current version.
If different, it indicates a probably "edit conflict": the submitted
edit is being made to a stale version of the model.
"""
edited_version = self.context['request'].data['edited_version']
current_version = reversion.get_for_date(
instance, timezone.now()).id
if not current_version == edited_version:
raise serializers.ValidationError(detail={
'detail':
'Edit conflict error! The current version for this object '
'does not match the reported version being edited.',
'current_version': current_version,
'submitted_data': self.context['request'].data,
})
评论列表
文章目录