13. Displaying the colors
Next, we'll represent product colors visually using color swatches imported from the library 'Font-Awesome'. This allows users to see the available color options at a glance.
Out of stock message
if len(item_stock) > 0 :
has_stock = True #? necessary in order to do a if on the html. if the product is out of stock, will show "Out of Stock"
else :
has_stock = FalseImporting the swatches
if len(item_stock) > 0 :
has_stock = True #? necessary in order to do a if on the html. if the product is out of stock, will show "Out of Stock"
colors = {item.color for item in item_stock} #? gets the colors of all products, uses sets '{}' to avoid duplicate colors
else :
has_stock = False
colors = {} #? needs to be declared
context = {'product': product, 'item_stock': item_stock, "has_stock" : has_stock, "colors" : colors}
base.html file beneath the previous link of the stylesheet we created


Last updated
