mirror of
https://github.com/netbox-community/netbox.git
synced 2025-07-21 19:47:20 -06:00
Fix denormalization logic to be compatible with loading fixture data
This commit is contained in:
parent
f11a6f0135
commit
56433cf855
@ -33,6 +33,10 @@ def update_denormalized_fields(sender, instance, created, raw, **kwargs):
|
|||||||
"""
|
"""
|
||||||
Check if the sender has denormalized fields registered, and update them as necessary.
|
Check if the sender has denormalized fields registered, and update them as necessary.
|
||||||
"""
|
"""
|
||||||
|
def _get_field_value(instance, field_name):
|
||||||
|
field = instance._meta.get_field(field_name)
|
||||||
|
return field.value_from_object(instance)
|
||||||
|
|
||||||
# Skip for new objects or those being populated from raw data
|
# Skip for new objects or those being populated from raw data
|
||||||
if created or raw:
|
if created or raw:
|
||||||
return
|
return
|
||||||
@ -45,7 +49,7 @@ def update_denormalized_fields(sender, instance, created, raw, **kwargs):
|
|||||||
}
|
}
|
||||||
update_params = {
|
update_params = {
|
||||||
# Map the denormalized field names to the instance's values
|
# Map the denormalized field names to the instance's values
|
||||||
denorm: getattr(instance, origin) for denorm, origin in mappings.items()
|
denorm: _get_field_value(instance, origin) for denorm, origin in mappings.items()
|
||||||
}
|
}
|
||||||
|
|
||||||
# TODO: Improve efficiency here by placing conditions on the query?
|
# TODO: Improve efficiency here by placing conditions on the query?
|
||||||
|
Loading…
Reference in New Issue
Block a user