diff --git a/shimatta_kenkyusho/parts/models.py b/shimatta_kenkyusho/parts/models.py index 1628ab8..c5b448e 100644 --- a/shimatta_kenkyusho/parts/models.py +++ b/shimatta_kenkyusho/parts/models.py @@ -83,20 +83,24 @@ class Storage(models.Model): # caching variable for subtrees storage_list = None - def get_path_components(self): + def get_path_components(self, top_level=None): chain = [] iterator = self chain.append(self) while iterator.parent_storage is not None: + + if top_level and iterator.parent_storage == top_level: + break + chain.append(iterator.parent_storage) iterator = iterator.parent_storage return chain - def get_full_path(self): + def get_full_path(self, top_level=None): output = '' - chain = self.get_path_components() + chain = self.get_path_components(top_level) for i in range(len(chain) - 1, -1, -1): output = output + '/' + chain[i].name diff --git a/shimatta_kenkyusho/parts/templatetags/__init__.py b/shimatta_kenkyusho/parts/templatetags/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/shimatta_kenkyusho/parts/templatetags/storage_tags.py b/shimatta_kenkyusho/parts/templatetags/storage_tags.py new file mode 100644 index 0000000..85ce3b2 --- /dev/null +++ b/shimatta_kenkyusho/parts/templatetags/storage_tags.py @@ -0,0 +1,9 @@ +import datetime +from django import template + +register = template.Library() + + +@register.filter(name="get_relative_storage_path") +def get_relative_storage_path(storage, top_level): + return f'.{storage.get_full_path(top_level)}' diff --git a/shimatta_kenkyusho/templates/parts/stocks-detail.html b/shimatta_kenkyusho/templates/parts/stocks-detail.html index 8945a24..8e2b54b 100644 --- a/shimatta_kenkyusho/templates/parts/stocks-detail.html +++ b/shimatta_kenkyusho/templates/parts/stocks-detail.html @@ -2,6 +2,7 @@ {% load qr_code %} {% load static %} {% load crispy_forms_tags %} +{% load storage_tags %} {% block content %}
@@ -97,6 +98,9 @@ {% if stock.component.manufacturer %} Manufacturer: {{stock.component.manufacturer}} {% endif %} + {% if stock.storage != storage %} +
{{ stock.storage|get_relative_storage_path:storage }}
+ {% endif %} {% if stock.lot %}
Lot: {{stock.lot}}
{% endif %}