make component types hierarchial
This commit is contained in:
parent
a300d66f66
commit
1c56dd44f9
@ -0,0 +1,19 @@
|
||||
# Generated by Django 3.2.5 on 2022-11-11 20:18
|
||||
|
||||
from django.db import migrations, models
|
||||
import django.db.models.deletion
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('parts', '0011_auto_20220110_1812'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AddField(
|
||||
model_name='componenttype',
|
||||
name='parent_class',
|
||||
field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.PROTECT, related_name='child_classes', to='parts.componenttype'),
|
||||
),
|
||||
]
|
@ -47,6 +47,7 @@ class ComponentType(models.Model):
|
||||
class Meta:
|
||||
ordering = ['class_name']
|
||||
class_name = models.CharField(max_length=50, unique=True)
|
||||
parent_class = models.ForeignKey('self', on_delete=models.PROTECT, related_name='child_classes', null=True, blank=True)
|
||||
passive = models.BooleanField()
|
||||
possible_parameter = models.ManyToManyField(ComponentParameterType, blank=True)
|
||||
key_parameter1 = models.ForeignKey(ComponentParameterType, on_delete=models.CASCADE, blank=True, null=True, related_name="type_param1")
|
||||
@ -54,7 +55,27 @@ class ComponentType(models.Model):
|
||||
key_parameter3 = models.ForeignKey(ComponentParameterType, on_delete=models.CASCADE, blank=True, null=True, related_name="type_param3")
|
||||
|
||||
def __str__(self):
|
||||
return '[' + self.class_name + ']'
|
||||
return self.get_full_path()
|
||||
|
||||
|
||||
def get_path_components(self):
|
||||
chain = []
|
||||
iterator = self
|
||||
chain.append(self)
|
||||
while iterator.parent_class is not None:
|
||||
chain.append(iterator.parent_class)
|
||||
iterator = iterator.parent_class
|
||||
|
||||
return chain
|
||||
|
||||
def get_full_path(self):
|
||||
output = ''
|
||||
|
||||
chain = self.get_path_components()
|
||||
|
||||
for i in range(len(chain) - 1, -1, -1):
|
||||
output = output + ' / ' + chain[i].class_name
|
||||
return output
|
||||
|
||||
class Storage(models.Model):
|
||||
class Meta:
|
||||
|
@ -186,8 +186,15 @@ class ComponentTypeDetailView(LoginRequiredMixin, BaseTemplateMixin, DetailView)
|
||||
pk_url_kwarg = 'uuid'
|
||||
template_name = 'parts/component-types-detail.html'
|
||||
|
||||
def get_breadcrumbs(self):
|
||||
crumbs = self.object.get_path_components()
|
||||
# Reverse list and drop the last element of the reversed list
|
||||
crumbs = crumbs[::-1][:-1]
|
||||
return crumbs
|
||||
|
||||
def get_context_data(self, **kwargs):
|
||||
context = super().get_context_data(**kwargs)
|
||||
context['breadcrumbs'] = self.get_breadcrumbs()
|
||||
return context
|
||||
|
||||
|
||||
|
@ -3,10 +3,18 @@
|
||||
|
||||
{% block content %}
|
||||
<div class="container">
|
||||
<nav aria-label="breadcrumb" class="fs-4">
|
||||
<ol class="breadcrumb">
|
||||
<li class="breadcrumb-item"></li>
|
||||
{% for crumb in breadcrumbs %}
|
||||
<li class="breadcrumb-item"><a href="{% url 'parts-componenttypes-detail' uuid=crumb.id %}">{{crumb.class_name}}</a></li>
|
||||
{% endfor %}
|
||||
<li class="breadcrumb-item active" aria-current="page">{{object.class_name}}</li>
|
||||
</ol>
|
||||
</nav>
|
||||
<div class="row">
|
||||
<div class="col-md">
|
||||
<h2>Component Type: {{object.class_name}}</h2>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
@ -22,7 +22,7 @@
|
||||
<a href="{% url 'parts-componenttypes-detail' uuid=t.id %}" class="text-decoration-none">
|
||||
<li class="list-group-item list-group-item-action d-flex flex-row align-items-center justify-content-between">
|
||||
<div class="p-2">
|
||||
{{t.class_name}}
|
||||
{{t}}
|
||||
</div>
|
||||
{% if t.passive %}
|
||||
<div class="p-2">
|
||||
|
Loading…
Reference in New Issue
Block a user