mirror of
https://github.com/inventree/InvenTree.git
synced 2026-09-02 10:18:42 +00:00
Add "primary" field to Note model
This commit is contained in:
@@ -87,6 +87,14 @@ class Migration(migrations.Migration):
|
|||||||
verbose_name="Update By",
|
verbose_name="Update By",
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
(
|
||||||
|
"primary",
|
||||||
|
models.BooleanField(
|
||||||
|
default=False,
|
||||||
|
help_text="Is this the primary note for the associated model?",
|
||||||
|
verbose_name="Primary",
|
||||||
|
),
|
||||||
|
)
|
||||||
],
|
],
|
||||||
options={
|
options={
|
||||||
"verbose_name": "Note",
|
"verbose_name": "Note",
|
||||||
|
|||||||
@@ -2935,8 +2935,23 @@ class Note(
|
|||||||
def save(self, *args, **kwargs):
|
def save(self, *args, **kwargs):
|
||||||
"""Perform custom save checks before saving a Note instance."""
|
"""Perform custom save checks before saving a Note instance."""
|
||||||
self.check_save()
|
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)
|
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):
|
def delete(self):
|
||||||
"""Perform custom delete checks before deleting a Parameter instance."""
|
"""Perform custom delete checks before deleting a Parameter instance."""
|
||||||
self.check_delete()
|
self.check_delete()
|
||||||
@@ -2976,6 +2991,12 @@ class Note(
|
|||||||
|
|
||||||
content_object = GenericForeignKey('model_type', 'model_id')
|
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(
|
title = models.CharField(
|
||||||
max_length=100, verbose_name=_('Title'), help_text=_('Note title')
|
max_length=100, verbose_name=_('Title'), help_text=_('Note title')
|
||||||
)
|
)
|
||||||
|
|||||||
Reference in New Issue
Block a user