mirror of
https://github.com/inventree/InvenTree.git
synced 2026-09-01 09:41:22 +00:00
Add link between Note and NotesImage
This commit is contained in:
@@ -106,4 +106,18 @@ class Migration(migrations.Migration):
|
|||||||
models.Model,
|
models.Model,
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
# Once the 'Note' model has been created, we can add the foreign key to the 'NotesImage' model
|
||||||
|
# This will (initially) allow null values, so that existing images are not affected
|
||||||
|
# After the data migration, we will come back and mark this field as non-nullable
|
||||||
|
migrations.AddField(
|
||||||
|
model_name="notesimage",
|
||||||
|
name="note",
|
||||||
|
field=models.ForeignKey(
|
||||||
|
blank=True,
|
||||||
|
null=True,
|
||||||
|
on_delete=django.db.models.deletion.SET_NULL,
|
||||||
|
to="common.note",
|
||||||
|
related_name='images',
|
||||||
|
),
|
||||||
|
),
|
||||||
]
|
]
|
||||||
|
|||||||
@@ -1767,42 +1767,6 @@ class NewsFeedEntry(models.Model):
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
def rename_notes_image(instance, filename):
|
|
||||||
"""Function for renaming uploading image file. Will store in the 'notes' directory."""
|
|
||||||
fname = os.path.basename(filename)
|
|
||||||
return os.path.join('notes', fname)
|
|
||||||
|
|
||||||
|
|
||||||
class NotesImage(models.Model):
|
|
||||||
"""Model for storing uploading images for the 'notes' fields of various models.
|
|
||||||
|
|
||||||
Simply stores the image file, for use in the 'notes' field (of any models which support markdown).
|
|
||||||
"""
|
|
||||||
|
|
||||||
image = models.ImageField(
|
|
||||||
upload_to=rename_notes_image, verbose_name=_('Image'), help_text=_('Image file')
|
|
||||||
)
|
|
||||||
|
|
||||||
user = models.ForeignKey(User, on_delete=models.SET_NULL, null=True, blank=True)
|
|
||||||
|
|
||||||
date = models.DateTimeField(auto_now_add=True)
|
|
||||||
|
|
||||||
model_type = models.CharField(
|
|
||||||
max_length=100,
|
|
||||||
blank=True,
|
|
||||||
null=True,
|
|
||||||
validators=[common.validators.validate_notes_model_type],
|
|
||||||
help_text=_('Target model type for this image'),
|
|
||||||
)
|
|
||||||
|
|
||||||
model_id = models.IntegerField(
|
|
||||||
help_text=_('Target model ID for this image'),
|
|
||||||
blank=True,
|
|
||||||
null=True,
|
|
||||||
default=None,
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
class CustomUnit(models.Model):
|
class CustomUnit(models.Model):
|
||||||
"""Model for storing custom physical unit definitions.
|
"""Model for storing custom physical unit definitions.
|
||||||
|
|
||||||
@@ -3119,6 +3083,46 @@ class Note(
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
def rename_notes_image(instance, filename):
|
||||||
|
"""Function for renaming uploading image file. Will store in the 'notes' directory."""
|
||||||
|
fname = os.path.basename(filename)
|
||||||
|
return os.path.join('notes', fname)
|
||||||
|
|
||||||
|
|
||||||
|
class NotesImage(models.Model):
|
||||||
|
"""Model for storing uploading images for the 'notes' fields of various models.
|
||||||
|
|
||||||
|
Simply stores the image file, for use in the 'notes' field (of any models which support markdown).
|
||||||
|
"""
|
||||||
|
|
||||||
|
image = models.ImageField(
|
||||||
|
upload_to=rename_notes_image, verbose_name=_('Image'), help_text=_('Image file')
|
||||||
|
)
|
||||||
|
|
||||||
|
user = models.ForeignKey(User, on_delete=models.SET_NULL, null=True, blank=True)
|
||||||
|
|
||||||
|
date = models.DateTimeField(auto_now_add=True)
|
||||||
|
|
||||||
|
model_type = models.CharField(
|
||||||
|
max_length=100,
|
||||||
|
blank=True,
|
||||||
|
null=True,
|
||||||
|
validators=[common.validators.validate_notes_model_type],
|
||||||
|
help_text=_('Target model type for this image'),
|
||||||
|
)
|
||||||
|
|
||||||
|
model_id = models.IntegerField(
|
||||||
|
help_text=_('Target model ID for this image'),
|
||||||
|
blank=True,
|
||||||
|
null=True,
|
||||||
|
default=None,
|
||||||
|
)
|
||||||
|
|
||||||
|
note = models.ForeignKey(
|
||||||
|
Note, on_delete=models.SET_NULL, null=True, blank=True, related_name='images'
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
class BarcodeScanResult(InvenTree.models.InvenTreeModel):
|
class BarcodeScanResult(InvenTree.models.InvenTreeModel):
|
||||||
"""Model for storing barcode scans results."""
|
"""Model for storing barcode scans results."""
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user