Display a part as 'starred' in the part table

This commit is contained in:
Oliver Walters 2020-04-13 21:30:17 +10:00
parent b850beb687
commit 124fab3eee
2 changed files with 10 additions and 0 deletions

View File

@ -147,6 +147,10 @@ function loadPartTable(table, url, options={}) {
display += `<span class='fas fa-tools label-right' title='Assembled part'></span>`; display += `<span class='fas fa-tools label-right' title='Assembled part'></span>`;
} }
if (row.starred) {
display += `<span class='fas fa-star label-right' title='Starred part'></span>`;
}
/* /*
if (row.component) { if (row.component) {
display = display + `<span class='fas fa-cogs label-right' title='Component part'></span>`; display = display + `<span class='fas fa-cogs label-right' title='Component part'></span>`;

View File

@ -258,12 +258,18 @@ class PartList(generics.ListCreateAPIView):
# Filter items which have an 'in_stock' level higher than 'minimum_stock' # Filter items which have an 'in_stock' level higher than 'minimum_stock'
data = data.filter(Q(in_stock__gte=F('minimum_stock'))) data = data.filter(Q(in_stock__gte=F('minimum_stock')))
# Get a list of the parts that this user has starred
starred_parts = [star.part.pk for star in self.request.user.starred_parts.all()]
# Reduce the number of lookups we need to do for the part categories # Reduce the number of lookups we need to do for the part categories
categories = {} categories = {}
for item in data: for item in data:
if item['image']: if item['image']:
# Is this part 'starred' for the current user?
item['starred'] = item['pk'] in starred_parts
img = item['image'] img = item['image']
# Use the 'thumbnail' image here instead of the full-size image # Use the 'thumbnail' image here instead of the full-size image