mirror of
https://github.com/inventree/InvenTree.git
synced 2025-07-13 08:21:26 +00:00
Add 'variant' field to Part model
- Display 'long_name' which is concatenation of name and variant
This commit is contained in:
@ -124,6 +124,7 @@ class Part(models.Model):
|
||||
|
||||
Attributes:
|
||||
name: Brief name for this part
|
||||
variant: Optional variant number for this part - Must be unique for the part name
|
||||
description: Longer form description of the part
|
||||
category: The PartCategory to which this part belongs
|
||||
IPN: Internal part number (optional)
|
||||
@ -142,6 +143,23 @@ class Part(models.Model):
|
||||
notes: Additional notes field for this part
|
||||
"""
|
||||
|
||||
class Meta:
|
||||
verbose_name = "Part"
|
||||
verbose_name_plural = "Parts"
|
||||
unique_together = [
|
||||
('name', 'variant')
|
||||
]
|
||||
|
||||
def __str__(self):
|
||||
return "{n} - {d}".format(n=self.long_name, d=self.description)
|
||||
|
||||
@property
|
||||
def long_name(self):
|
||||
name = self.name
|
||||
if self.variant:
|
||||
name += " | " + self.variant
|
||||
return name
|
||||
|
||||
def get_absolute_url(self):
|
||||
""" Return the web URL for viewing this part """
|
||||
return reverse('part-detail', kwargs={'pk': self.id})
|
||||
@ -154,7 +172,9 @@ class Part(models.Model):
|
||||
else:
|
||||
return static('/img/blank_image.png')
|
||||
|
||||
name = models.CharField(max_length=100, unique=True, blank=False, help_text='Part name (must be unique)')
|
||||
name = models.CharField(max_length=100, blank=False, help_text='Part name')
|
||||
|
||||
variant = models.CharField(max_length=32, blank=True, help_text='Part variant or revision code')
|
||||
|
||||
description = models.CharField(max_length=250, blank=False, help_text='Part description')
|
||||
|
||||
@ -228,9 +248,6 @@ class Part(models.Model):
|
||||
|
||||
notes = models.TextField(blank=True)
|
||||
|
||||
def __str__(self):
|
||||
return "{n} - {d}".format(n=self.name, d=self.description)
|
||||
|
||||
def format_barcode(self):
|
||||
""" Return a JSON string for formatting a barcode for this Part object """
|
||||
|
||||
@ -243,10 +260,6 @@ class Part(models.Model):
|
||||
}
|
||||
)
|
||||
|
||||
class Meta:
|
||||
verbose_name = "Part"
|
||||
verbose_name_plural = "Parts"
|
||||
|
||||
@property
|
||||
def category_path(self):
|
||||
if self.category:
|
||||
|
Reference in New Issue
Block a user