mirror of
https://github.com/netbox-community/netbox.git
synced 2025-08-18 05:28:16 -06:00
Refactor logic
This commit is contained in:
parent
3704367366
commit
fd8a97cb3e
@ -68,25 +68,20 @@ def handle_changed_object(sender, instance, **kwargs):
|
|||||||
else:
|
else:
|
||||||
return
|
return
|
||||||
|
|
||||||
# Record an ObjectChange if applicable
|
# Create/update an ObejctChange record for this change
|
||||||
objectchange = instance.to_objectchange(action)
|
objectchange = instance.to_objectchange(action)
|
||||||
resave_objectchange = False
|
# If this is a many-to-many field change, check for a previous ObjectChange instance recorded
|
||||||
if m2m_changed:
|
# for this object by this request and update it
|
||||||
qs = ObjectChange.objects.filter(
|
if m2m_changed and (
|
||||||
|
prev_change := ObjectChange.objects.filter(
|
||||||
changed_object_type=ContentType.objects.get_for_model(instance),
|
changed_object_type=ContentType.objects.get_for_model(instance),
|
||||||
changed_object_id=instance.pk,
|
changed_object_id=instance.pk,
|
||||||
request_id=request.id
|
request_id=request.id
|
||||||
)
|
).first()
|
||||||
if not qs:
|
):
|
||||||
resave_objectchange = True
|
prev_change.postchange_data = objectchange.postchange_data
|
||||||
else:
|
prev_change.save()
|
||||||
qs.update(
|
elif objectchange and objectchange.has_changes:
|
||||||
postchange_data=objectchange.postchange_data
|
|
||||||
)
|
|
||||||
else:
|
|
||||||
resave_objectchange = True
|
|
||||||
|
|
||||||
if resave_objectchange and objectchange and objectchange.has_changes:
|
|
||||||
objectchange.user = request.user
|
objectchange.user = request.user
|
||||||
objectchange.request_id = request.id
|
objectchange.request_id = request.id
|
||||||
objectchange.save()
|
objectchange.save()
|
||||||
|
Loading…
Reference in New Issue
Block a user