From ab0da25de8b44a068ff72651cf7929ac33013028 Mon Sep 17 00:00:00 2001 From: Oliver Walters Date: Thu, 21 May 2026 07:26:28 +0000 Subject: [PATCH] Add "primary" field to Note model --- .../InvenTree/common/migrations/0042_note.py | 8 +++++++ src/backend/InvenTree/common/models.py | 21 +++++++++++++++++++ 2 files changed, 29 insertions(+) diff --git a/src/backend/InvenTree/common/migrations/0042_note.py b/src/backend/InvenTree/common/migrations/0042_note.py index 4d4dbea255..409eec9f5c 100644 --- a/src/backend/InvenTree/common/migrations/0042_note.py +++ b/src/backend/InvenTree/common/migrations/0042_note.py @@ -87,6 +87,14 @@ class Migration(migrations.Migration): verbose_name="Update By", ), ), + ( + "primary", + models.BooleanField( + default=False, + help_text="Is this the primary note for the associated model?", + verbose_name="Primary", + ), + ) ], options={ "verbose_name": "Note", diff --git a/src/backend/InvenTree/common/models.py b/src/backend/InvenTree/common/models.py index 332e7fedfd..cc0e3566a3 100644 --- a/src/backend/InvenTree/common/models.py +++ b/src/backend/InvenTree/common/models.py @@ -2935,8 +2935,23 @@ class Note( def save(self, *args, **kwargs): """Perform custom save checks before saving a Note instance.""" self.check_save() + + others = Note.objects.filter( + model_type=self.model_type, model_id=self.model_id + ).exclude(pk=self.pk) + + # If this is the *only* note for this model instance, then set it as the primary note + if not others.exists(): + self.primary = True + super().save(*args, **kwargs) + # Once this note is saved, mark other notes as non-primary + if self.primary: + Note.objects.filter( + model_type=self.model_type, model_id=self.model_id + ).exclude(pk=self.pk).update(primary=False) + def delete(self): """Perform custom delete checks before deleting a Parameter instance.""" self.check_delete() @@ -2976,6 +2991,12 @@ class Note( content_object = GenericForeignKey('model_type', 'model_id') + primary = models.BooleanField( + default=False, + verbose_name=_('Primary'), + help_text=_('Is this the primary note for the associated model?'), + ) + title = models.CharField( max_length=100, verbose_name=_('Title'), help_text=_('Note title') )