2
0
mirror of https://github.com/inventree/InvenTree.git synced 2025-06-12 10:05:39 +00:00

Begin to add views for part models

- List BOM items
- Show category listing as linked items
- Fix some pathing issues with InvenTreeTree class
This commit is contained in:
Oliver
2018-04-13 22:36:59 +10:00
parent 77fe0dc542
commit bd46f66d6b
15 changed files with 182 additions and 25 deletions

View File

@ -36,7 +36,7 @@ class Part(models.Model):
IPN = models.CharField(max_length=100, blank=True)
# Part category - all parts must be assigned to a category
category = models.ForeignKey(PartCategory, on_delete=models.CASCADE)
category = models.ForeignKey(PartCategory, on_delete=models.CASCADE, related_name='parts')
# Minimum "allowed" stock level
minimum_stock = models.PositiveIntegerField(default=0, validators=[MinValueValidator(0)])
@ -75,11 +75,21 @@ class Part(models.Model):
result = stocks.aggregate(total=Sum('quantity'))
return result['total']
@property
def bomItemCount(self):
return self.bom_items.all().count()
@property
def usedInCount(self):
return self.used_in.all().count()
"""
@property
def projects(self):
""" Return a list of unique projects that this part is associated with.
" Return a list of unique projects that this part is associated with.
A part may be used in zero or more projects.
"""
"
project_ids = set()
project_parts = self.projectpart_set.all()
@ -92,6 +102,6 @@ class Part(models.Model):
projects.append(pp.project)
return projects
"""