Home Information - Your home, your data, organized.
Python
AttributeValueHistory backend for tracking changes (#104)
cassandra-ai-agentbc63df99ab03
diff --git a/src/hi/apps/attribute/models.py b/src/hi/apps/attribute/models.pyindex 8e653da3..45e678de 100644--- a/src/hi/apps/attribute/models.py+++ b/src/hi/apps/attribute/models.py@@ -17,6 +17,34 @@ from .enums import (logger = logging.getLogger(__name__)+class AttributeValueHistoryModel(models.Model):+ """+ Abstract base class for tracking attribute value changes.+ Each concrete attribute subclass should have its own history model+ that defines the foreign key to its specific attribute type.++ Only tracks value-based attributes (Text, Boolean, Integer, Float, etc.).+ File attributes are excluded and will be handled separately.+ """++ class Meta:+ abstract = True+ ordering = ['-changed_datetime']++ value = models.TextField(+ 'Value',+ blank=True, null=True,+ )+ changed_datetime = models.DateTimeField(+ 'Changed',+ auto_now_add=True,+ db_index=True,+ )++ def __str__(self):+ return f'Changed at {self.changed_datetime}'++class AttributeModel(models.Model):class Meta:@@ -136,6 +164,8 @@ class AttributeModel(models.Model):return dict()def save(self, *args, **kwargs):+ # Skip history tracking for kwargs that disable it+ track_history = kwargs.pop('track_history', True)if self.file_value and self.file_value.name:self.file_value.field.upload_to = self.get_upload_to()@@ -143,10 +173,35 @@ class AttributeModel(models.Model):self.value = self.file_value.nameif not self.pk or not self.__class__.objects.filter( pk = self.pk ).exists():self.file_value.name = generate_unique_filename( self.file_value.name )-++ # Save the attribute firstsuper().save(*args, **kwargs)++ # Track history for value-based attributes only AFTER saving+ if track_history and not self.value_type.is_file:+ self._create_history_record()+return+ def _create_history_record(self):+ """Create a history record for this attribute's value change."""+ # Get the history model class for this concrete attribute type+ history_model_class = self._get_history_model_class()+ if not history_model_class:+ return++ # Create history record+ history_model_class.objects.create(+ attribute=self,+ value=self.value+ )++ def _get_history_model_class(self):+ """Get the corresponding history model class for this attribute type."""+ # This will be implemented by each concrete subclass or use introspection+ # For now, return None to avoid errors - will be implemented with concrete models+ return None+def delete( self, *args, **kwargs ):""" Deleting file from MEDIA_ROOT on best effort basis. Ignore if fails. """diff --git a/src/hi/apps/attribute/tests/test_models.py b/src/hi/apps/attribute/tests/test_models.pyindex e19c2a7f..00316b8c 100644--- a/src/hi/apps/attribute/tests/test_models.py+++ b/src/hi/apps/attribute/tests/test_models.py@@ -258,3 +258,4 @@ class TestAttributeModel(BaseTestCase):# __repr__ should equal __str__self.assertEqual(repr(attr), str(attr))return+diff --git a/src/hi/apps/config/admin.py b/src/hi/apps/config/admin.pyindex 0c5011e7..2c15d6db 100644--- a/src/hi/apps/config/admin.py+++ b/src/hi/apps/config/admin.py@@ -9,6 +9,14 @@ class SubsystemAttributeInLine(admin.TabularInline):show_change_link = True+class SubsystemAttributeHistoryInLine(admin.TabularInline):+ model = models.SubsystemAttributeHistory+ extra = 0+ show_change_link = True+ readonly_fields = ('value', 'changed_datetime')+ can_delete = False++@admin.register(models.Subsystem)class SubsystemAdmin(admin.ModelAdmin):show_full_result_count = False@@ -21,3 +29,23 @@ class SubsystemAdmin(admin.ModelAdmin):inlines = [ SubsystemAttributeInLine, ]+[email protected](models.SubsystemAttribute)+class SubsystemAttributeAdmin(admin.ModelAdmin):++ show_full_result_count = False++ list_display = (+ 'subsystem',+ 'name',+ 'value',+ 'value_type_str',+ 'attribute_type_str',+ 'setting_key',+ 'created_datetime',+ )++ search_fields = ['name', 'subsystem__name', 'setting_key']+ readonly_fields = ('subsystem', 'created_datetime')+ inlines = [SubsystemAttributeHistoryInLine]+diff --git a/src/hi/apps/config/migrations/0004_subsystemattributehistory.py b/src/hi/apps/config/migrations/0004_subsystemattributehistory.pynew file mode 100644index 00000000..375efad0--- /dev/null+++ b/src/hi/apps/config/migrations/0004_subsystemattributehistory.py@@ -0,0 +1,57 @@+# Generated by Django 4.2.22 on 2025-08-22 20:21++from django.db import migrations, models+import django.db.models.deletion+++class Migration(migrations.Migration):++ dependencies = [+ ("config", "0003_add_weather_settings"),+ ]++ operations = [+ migrations.CreateModel(+ name="SubsystemAttributeHistory",+ fields=[+ (+ "id",+ models.BigAutoField(+ auto_created=True,+ primary_key=True,+ serialize=False,+ verbose_name="ID",+ ),+ ),+ (+ "value",+ models.TextField(blank=True, null=True, verbose_name="Value"),+ ),+ (+ "changed_datetime",+ models.DateTimeField(+ auto_now_add=True, db_index=True, verbose_name="Changed"+ ),+ ),+ (+ "attribute",+ models.ForeignKey(+ on_delete=django.db.models.deletion.CASCADE,+ related_name="history",+ to="config.subsystemattribute",+ verbose_name="Subsystem Attribute",+ ),+ ),+ ],+ options={+ "verbose_name": "Subsystem Attribute History",+ "verbose_name_plural": "Subsystem Attribute History",+ "indexes": [+ models.Index(+ fields=["attribute", "-changed_datetime"],+ name="config_subs_attribu_2cbd30_idx",+ )+ ],+ },+ ),+ ]diff --git a/src/hi/apps/config/models.py b/src/hi/apps/config/models.pyindex 7c7d78e2..d0dc5d2f 100644--- a/src/hi/apps/config/models.py+++ b/src/hi/apps/config/models.py@@ -1,6 +1,6 @@from django.db import models-from hi.apps.attribute.models import AttributeModel+from hi.apps.attribute.models import AttributeModel, AttributeValueHistoryModelclass Subsystem( models.Model ):@@ -50,3 +50,25 @@ class SubsystemAttribute( AttributeModel ):def get_upload_to(self):return 'settings/'++ def _get_history_model_class(self):+ """Return the history model class for SubsystemAttribute."""+ return SubsystemAttributeHistory+++class SubsystemAttributeHistory(AttributeValueHistoryModel):+ """History tracking for SubsystemAttribute changes."""++ attribute = models.ForeignKey(+ SubsystemAttribute,+ related_name='history',+ verbose_name='Subsystem Attribute',+ on_delete=models.CASCADE,+ )++ class Meta:+ verbose_name = 'Subsystem Attribute History'+ verbose_name_plural = 'Subsystem Attribute History'+ indexes = [+ models.Index(fields=['attribute', '-changed_datetime']),+ ]diff --git a/src/hi/apps/entity/admin.py b/src/hi/apps/entity/admin.pyindex fbed48e1..4da6f39b 100644--- a/src/hi/apps/entity/admin.py+++ b/src/hi/apps/entity/admin.py@@ -11,6 +11,14 @@ class EntityAttributeInLine(admin.TabularInline):extra = 0show_change_link = True++class EntityAttributeHistoryInLine(admin.TabularInline):+ model = models.EntityAttributeHistory+ extra = 0+ show_change_link = True+ readonly_fields = ('value', 'changed_datetime')+ can_delete = False+class StateInLine(admin.TabularInline):model = models.EntityState@@ -114,4 +122,23 @@ class EntityStateDelegationAdmin(admin.ModelAdmin):search_fields = ['entity__name']readonly_fields = ( 'entity_state', 'delegate_entity', )++[email protected](models.EntityAttribute)+class EntityAttributeAdmin(admin.ModelAdmin):++ show_full_result_count = False++ list_display = (+ 'entity',+ 'name',+ 'value',+ 'value_type_str',+ 'attribute_type_str',+ 'created_datetime',+ )++ search_fields = ['name', 'entity__name']+ readonly_fields = ('entity', 'created_datetime')+ inlines = [EntityAttributeHistoryInLine]diff --git a/src/hi/apps/entity/migrations/0005_entityattributehistory.py b/src/hi/apps/entity/migrations/0005_entityattributehistory.pynew file mode 100644index 00000000..eeb7a15f--- /dev/null+++ b/src/hi/apps/entity/migrations/0005_entityattributehistory.py@@ -0,0 +1,57 @@+# Generated by Django 4.2.22 on 2025-08-22 20:21++from django.db import migrations, models+import django.db.models.deletion+++class Migration(migrations.Migration):++ dependencies = [+ ("entity", "0004_alter_entity_integration_payload"),+ ]++ operations = [+ migrations.CreateModel(+ name="EntityAttributeHistory",+ fields=[+ (+ "id",+ models.BigAutoField(+ auto_created=True,+ primary_key=True,+ serialize=False,+ verbose_name="ID",+ ),+ ),+ (+ "value",+ models.TextField(blank=True, null=True, verbose_name="Value"),+ ),+ (+ "changed_datetime",+ models.DateTimeField(+ auto_now_add=True, db_index=True, verbose_name="Changed"+ ),+ ),+ (+ "attribute",+ models.ForeignKey(+ on_delete=django.db.models.deletion.CASCADE,+ related_name="history",+ to="entity.entityattribute",+ verbose_name="Entity Attribute",+ ),+ ),+ ],+ options={+ "verbose_name": "Entity Attribute History",+ "verbose_name_plural": "Entity Attribute History",+ "indexes": [+ models.Index(+ fields=["attribute", "-changed_datetime"],+ name="entity_enti_attribu_d34f67_idx",+ )+ ],+ },+ ),+ ]diff --git a/src/hi/apps/entity/models.py b/src/hi/apps/entity/models.pyindex e533d08e..90db13f5 100644--- a/src/hi/apps/entity/models.py+++ b/src/hi/apps/entity/models.py@@ -10,7 +10,7 @@ from hi.apps.location.models import (LocationItemPathModel,LocationView,)-from hi.apps.attribute.models import AttributeModel+from hi.apps.attribute.models import AttributeModel, AttributeValueHistoryModelfrom hi.integrations.models import IntegrationDetailsModelfrom hi.enums import ItemType@@ -115,7 +115,11 @@ class EntityAttribute( AttributeModel ):def get_upload_to(self):return 'entity/attributes/'-++ def _get_history_model_class(self):+ """Return the history model class for EntityAttribute."""+ return EntityAttributeHistory+class EntityState( models.Model ):"""@@ -400,3 +404,21 @@ class EntityView(models.Model):name = 'entity_view_entity_location_view', ),]++class EntityAttributeHistory(AttributeValueHistoryModel):+ """History tracking for EntityAttribute changes."""++ attribute = models.ForeignKey(+ EntityAttribute,+ related_name='history',+ verbose_name='Entity Attribute',+ on_delete=models.CASCADE,+ )++ class Meta:+ verbose_name = 'Entity Attribute History'+ verbose_name_plural = 'Entity Attribute History'+ indexes = [+ models.Index(fields=['attribute', '-changed_datetime']),+ ]+diff --git a/src/hi/apps/entity/tests/test_attribute_history.py b/src/hi/apps/entity/tests/test_attribute_history.pynew file mode 100644index 00000000..f4ad764d--- /dev/null+++ b/src/hi/apps/entity/tests/test_attribute_history.py@@ -0,0 +1,206 @@+import logging++from hi.apps.entity.models import Entity, EntityAttribute, EntityAttributeHistory+from hi.testing.base_test_case import BaseTestCase++logging.disable(logging.CRITICAL)+++class EntityAttributeHistoryTestCase(BaseTestCase):+ """Tests for EntityAttribute history tracking functionality."""++ def test_attribute_history_creation_on_value_change(self):+ """Test that history records are created when attribute values change - core business logic."""+ # Create entity and attribute+ entity = Entity.objects.create(+ name='Test Entity',+ entity_type_str='GENERAL',+ integration_id='test.entity',+ integration_name='test_integration'+ )++ attr = EntityAttribute.objects.create(+ entity=entity,+ name='test_attr',+ value='initial_value',+ value_type_str='TEXT',+ attribute_type_str='CUSTOM'+ )++ # Verify initial history record was created+ initial_history_count = EntityAttributeHistory.objects.filter(attribute=attr).count()+ self.assertEqual(initial_history_count, 1)++ # Update the attribute value+ attr.value = 'updated_value'+ attr.save()++ # Verify new history record was created+ updated_history_count = EntityAttributeHistory.objects.filter(attribute=attr).count()+ self.assertEqual(updated_history_count, 2)++ # Verify the latest history record contains the new value+ latest_history = EntityAttributeHistory.objects.filter(attribute=attr).order_by('-changed_datetime').first()+ self.assertEqual(latest_history.value, 'updated_value')+ return++ def test_attribute_history_skipped_for_file_attributes(self):+ """Test that file attributes do not create history records - important exclusion logic."""+ # Create entity+ entity = Entity.objects.create(+ name='Test Entity',+ entity_type_str='GENERAL',+ integration_id='test.entity',+ integration_name='test_integration'+ )++ # Create file attribute+ attr = EntityAttribute.objects.create(+ entity=entity,+ name='test_file_attr',+ value_type_str='FILE',+ attribute_type_str='CUSTOM'+ )++ # Verify no history records were created for file attribute+ history_count = EntityAttributeHistory.objects.filter(attribute=attr).count()+ self.assertEqual(history_count, 0)+ return++ def test_attribute_history_disabled_with_track_history_false(self):+ """Test that history tracking can be disabled via save parameter - control mechanism."""+ # Create entity and attribute with history tracking disabled+ entity = Entity.objects.create(+ name='Test Entity',+ entity_type_str='GENERAL',+ integration_id='test.entity',+ integration_name='test_integration'+ )++ attr = EntityAttribute(+ entity=entity,+ name='test_attr',+ value='initial_value',+ value_type_str='TEXT',+ attribute_type_str='CUSTOM'+ )+ attr.save(track_history=False) # Disable history tracking++ # Verify no history record was created+ history_count = EntityAttributeHistory.objects.filter(attribute=attr).count()+ self.assertEqual(history_count, 0)+ return++ def test_attribute_get_history_model_class_mapping(self):+ """Test _get_history_model_class returns correct model class - critical mapping logic."""+ # Test EntityAttribute mapping+ entity = Entity.objects.create(+ name='Test Entity',+ entity_type_str='GENERAL',+ integration_id='test.entity',+ integration_name='test_integration'+ )+ entity_attr = EntityAttribute(+ entity=entity,+ name='entity_attr',+ value_type_str='TEXT',+ attribute_type_str='CUSTOM'+ )+ self.assertEqual(entity_attr._get_history_model_class(), EntityAttributeHistory)+ return++ def test_attribute_history_cascade_deletion(self):+ """Test that history records are deleted when attribute is deleted - database constraint behavior."""+ # Create entity and attribute with history+ entity = Entity.objects.create(+ name='Test Entity',+ entity_type_str='GENERAL',+ integration_id='test.entity',+ integration_name='test_integration'+ )++ attr = EntityAttribute.objects.create(+ entity=entity,+ name='test_attr',+ value='test_value',+ value_type_str='TEXT',+ attribute_type_str='CUSTOM'+ )++ # Update to create multiple history records+ attr.value = 'updated_value'+ attr.save()++ # Verify history records exist+ history_count = EntityAttributeHistory.objects.filter(attribute=attr).count()+ self.assertEqual(history_count, 2)++ # Delete the attribute+ attr.delete()++ # Verify all history records are deleted (cascade)+ history_count = EntityAttributeHistory.objects.filter(attribute=attr).count()+ self.assertEqual(history_count, 0)+ return++ def test_multiple_attribute_updates_create_sequential_history(self):+ """Test that multiple updates create proper history sequence - workflow verification."""+ # Create entity and attribute+ entity = Entity.objects.create(+ name='Test Entity',+ entity_type_str='GENERAL',+ integration_id='test.entity',+ integration_name='test_integration'+ )++ attribute = EntityAttribute.objects.create(+ entity=entity,+ name='sequential_test',+ value='value_1',+ value_type_str='TEXT',+ attribute_type_str='CUSTOM'+ )++ # Perform multiple updates+ for i in range(2, 6): # values 2, 3, 4, 5+ attribute.value = f'value_{i}'+ attribute.save()++ # Verify all history records exist+ history_records = EntityAttributeHistory.objects.filter(attribute=attribute).order_by('-changed_datetime')+ self.assertEqual(history_records.count(), 5) # Initial + 4 updates++ # Verify values are in correct order (newest first)+ expected_values = ['value_5', 'value_4', 'value_3', 'value_2', 'value_1']+ actual_values = [record.value for record in history_records]+ self.assertEqual(actual_values, expected_values)+ return++ def test_boolean_attribute_history(self):+ """Test boolean attribute value changes create proper history - data type verification."""+ # Create entity and boolean attribute+ entity = Entity.objects.create(+ name='Test Entity',+ entity_type_str='GENERAL',+ integration_id='test.entity',+ integration_name='test_integration'+ )++ attribute = EntityAttribute.objects.create(+ entity=entity,+ name='boolean_test',+ value='True',+ value_type_str='BOOLEAN',+ attribute_type_str='CUSTOM'+ )++ # Update boolean value+ attribute.value = 'False'+ attribute.save()++ # Verify history captures the boolean change+ history_records = EntityAttributeHistory.objects.filter(attribute=attribute).order_by('-changed_datetime')+ self.assertEqual(history_records.count(), 2)+ self.assertEqual(history_records[0].value, 'False') # Latest+ self.assertEqual(history_records[1].value, 'True') # Original+ returndiff --git a/src/hi/apps/location/admin.py b/src/hi/apps/location/admin.pyindex 752a56f2..36b2ce4f 100644--- a/src/hi/apps/location/admin.py+++ b/src/hi/apps/location/admin.py@@ -8,6 +8,20 @@ class LocationViewInLine(admin.TabularInline):extra = 0show_change_link = True++class LocationAttributeInLine(admin.TabularInline):+ model = models.LocationAttribute+ extra = 0+ show_change_link = True+++class LocationAttributeHistoryInLine(admin.TabularInline):+ model = models.LocationAttributeHistory+ extra = 0+ show_change_link = True+ readonly_fields = ('value', 'changed_datetime')+ can_delete = False+@admin.register(models.Location)class LocationAdmin(admin.ModelAdmin):@@ -25,7 +39,7 @@ class LocationAdmin(admin.ModelAdmin):search_fields = ['name']ordering = ( 'order_id', )- inlines = [ LocationViewInLine, ]+ inlines = [ LocationViewInLine, LocationAttributeInLine, ]@admin.register(models.LocationView)@@ -46,3 +60,22 @@ class LocationViewAdmin(admin.ModelAdmin):search_fields = ['name']ordering = ( 'order_id', )++[email protected](models.LocationAttribute)+class LocationAttributeAdmin(admin.ModelAdmin):++ show_full_result_count = False++ list_display = (+ 'location',+ 'name',+ 'value',+ 'value_type_str',+ 'attribute_type_str',+ 'created_datetime',+ )++ search_fields = ['name', 'location__name']+ readonly_fields = ('location', 'created_datetime')+ inlines = [LocationAttributeHistoryInLine]diff --git a/src/hi/apps/location/migrations/0002_locationattributehistory.py b/src/hi/apps/location/migrations/0002_locationattributehistory.pynew file mode 100644index 00000000..033386c5--- /dev/null+++ b/src/hi/apps/location/migrations/0002_locationattributehistory.py@@ -0,0 +1,57 @@+# Generated by Django 4.2.22 on 2025-08-22 20:21++from django.db import migrations, models+import django.db.models.deletion+++class Migration(migrations.Migration):++ dependencies = [+ ("location", "0001_initial"),+ ]++ operations = [+ migrations.CreateModel(+ name="LocationAttributeHistory",+ fields=[+ (+ "id",+ models.BigAutoField(+ auto_created=True,+ primary_key=True,+ serialize=False,+ verbose_name="ID",+ ),+ ),+ (+ "value",+ models.TextField(blank=True, null=True, verbose_name="Value"),+ ),+ (+ "changed_datetime",+ models.DateTimeField(+ auto_now_add=True, db_index=True, verbose_name="Changed"+ ),+ ),+ (+ "attribute",+ models.ForeignKey(+ on_delete=django.db.models.deletion.CASCADE,+ related_name="history",+ to="location.locationattribute",+ verbose_name="Location Attribute",+ ),+ ),+ ],+ options={+ "verbose_name": "Location Attribute History",+ "verbose_name_plural": "Location Attribute History",+ "indexes": [+ models.Index(+ fields=["attribute", "-changed_datetime"],+ name="location_lo_attribu_dc1583_idx",+ )+ ],+ },+ ),+ ]diff --git a/src/hi/apps/location/models.py b/src/hi/apps/location/models.pyindex 33083479..487bdf43 100644--- a/src/hi/apps/location/models.py+++ b/src/hi/apps/location/models.py@@ -4,7 +4,7 @@ from django.core.files.storage import default_storagefrom django.db import modelsfrom hi.apps.common.svg_models import SvgDecimalField, SvgItemPositionBounds, SvgViewBox-from hi.apps.attribute.models import AttributeModel+from hi.apps.attribute.models import AttributeModel, AttributeValueHistoryModelfrom hi.enums import ItemTypefrom hi.models import ItemTypeModelMixin@@ -125,6 +125,10 @@ class LocationAttribute( AttributeModel ):def get_upload_to(self):return 'location/attributes/'+ def _get_history_model_class(self):+ """Return the history model class for LocationAttribute."""+ return LocationAttributeHistory+class LocationView( models.Model, ItemTypeModelMixin ):@@ -277,3 +281,21 @@ class LocationItemPathModel( models.Model ):@propertydef location_item(self) -> LocationItemModelMixin:raise NotImplementedError('Subclasses must implement this method.')+++class LocationAttributeHistory(AttributeValueHistoryModel):+ """History tracking for LocationAttribute changes."""++ attribute = models.ForeignKey(+ LocationAttribute,+ related_name='history',+ verbose_name='Location Attribute',+ on_delete=models.CASCADE,+ )++ class Meta:+ verbose_name = 'Location Attribute History'+ verbose_name_plural = 'Location Attribute History'+ indexes = [+ models.Index(fields=['attribute', '-changed_datetime']),+ ]diff --git a/src/hi/integrations/admin.py b/src/hi/integrations/admin.pyindex ceec7fd3..145809df 100644--- a/src/hi/integrations/admin.py+++ b/src/hi/integrations/admin.py@@ -9,6 +9,14 @@ class IntegrationAttributeInLine(admin.TabularInline):show_change_link = True+class IntegrationAttributeHistoryInLine(admin.TabularInline):+ model = models.IntegrationAttributeHistory+ extra = 0+ show_change_link = True+ readonly_fields = ('value', 'changed_datetime')+ can_delete = False++@admin.register(models.Integration)class IntegrationAdmin(admin.ModelAdmin):show_full_result_count = False@@ -21,3 +29,22 @@ class IntegrationAdmin(admin.ModelAdmin):)inlines = [ IntegrationAttributeInLine, ]++[email protected](models.IntegrationAttribute)+class IntegrationAttributeAdmin(admin.ModelAdmin):++ show_full_result_count = False++ list_display = (+ 'integration',+ 'name',+ 'value',+ 'value_type_str',+ 'attribute_type_str',+ 'created_datetime',+ )++ search_fields = ['name', 'integration__integration_id']+ readonly_fields = ('integration', 'created_datetime')+ inlines = [IntegrationAttributeHistoryInLine]diff --git a/src/hi/integrations/migrations/0002_integrationattributehistory.py b/src/hi/integrations/migrations/0002_integrationattributehistory.pynew file mode 100644index 00000000..42eb2c61--- /dev/null+++ b/src/hi/integrations/migrations/0002_integrationattributehistory.py@@ -0,0 +1,57 @@+# Generated by Django 4.2.22 on 2025-08-22 20:21++from django.db import migrations, models+import django.db.models.deletion+++class Migration(migrations.Migration):++ dependencies = [+ ("integrations", "0001_initial"),+ ]++ operations = [+ migrations.CreateModel(+ name="IntegrationAttributeHistory",+ fields=[+ (+ "id",+ models.BigAutoField(+ auto_created=True,+ primary_key=True,+ serialize=False,+ verbose_name="ID",+ ),+ ),+ (+ "value",+ models.TextField(blank=True, null=True, verbose_name="Value"),+ ),+ (+ "changed_datetime",+ models.DateTimeField(+ auto_now_add=True, db_index=True, verbose_name="Changed"+ ),+ ),+ (+ "attribute",+ models.ForeignKey(+ on_delete=django.db.models.deletion.CASCADE,+ related_name="history",+ to="integrations.integrationattribute",+ verbose_name="Integration Attribute",+ ),+ ),+ ],+ options={+ "verbose_name": "Integration Attribute History",+ "verbose_name_plural": "Integration Attribute History",+ "indexes": [+ models.Index(+ fields=["attribute", "-changed_datetime"],+ name="integration_attribu_e98869_idx",+ )+ ],+ },+ ),+ ]diff --git a/src/hi/integrations/models.py b/src/hi/integrations/models.pyindex 8b0e5991..2e01f6b0 100644--- a/src/hi/integrations/models.py+++ b/src/hi/integrations/models.py@@ -2,7 +2,7 @@ from typing import Dictfrom django.db import models-from hi.apps.attribute.models import AttributeModel+from hi.apps.attribute.models import AttributeModel, AttributeValueHistoryModelfrom .transient_models import IntegrationKey, IntegrationDetailsfrom .managers import IntegrationDetailsManager@@ -62,6 +62,10 @@ class IntegrationAttribute( AttributeModel ):def get_upload_to(self):return 'integration/attributes/'++ def _get_history_model_class(self):+ """Return the history model class for IntegrationAttribute."""+ return IntegrationAttributeHistoryclass IntegrationDetailsModel( models.Model ):@@ -133,3 +137,21 @@ class IntegrationDetailsModel( models.Model ):self.save()return changed_fields+++class IntegrationAttributeHistory(AttributeValueHistoryModel):+ """History tracking for IntegrationAttribute changes."""++ attribute = models.ForeignKey(+ IntegrationAttribute,+ related_name='history',+ verbose_name='Integration Attribute',+ on_delete=models.CASCADE,+ )++ class Meta:+ verbose_name = 'Integration Attribute History'+ verbose_name_plural = 'Integration Attribute History'+ indexes = [+ models.Index(fields=['attribute', '-changed_datetime']),+ ]