Added part category path string to serializer

This commit is contained in:
Oliver 2018-04-24 17:54:08 +10:00
parent 25fcd3e9f1
commit f46c09e3a7
4 changed files with 11 additions and 4 deletions

View File

@ -153,6 +153,12 @@ class Part(models.Model):
verbose_name = "Part" verbose_name = "Part"
verbose_name_plural = "Parts" verbose_name_plural = "Parts"
@property
def category_path(self):
if self.category:
return self.category.pathstring
return ''
@property @property
def available_stock(self): def available_stock(self):
""" """

View File

@ -17,6 +17,7 @@ class PartSerializer(serializers.ModelSerializer):
'URL', # Link to an external URL (optional) 'URL', # Link to an external URL (optional)
'description', 'description',
'category', 'category',
'category_path',
'total_stock', 'total_stock',
'available_stock', 'available_stock',
'units', 'units',

View File

@ -33,7 +33,9 @@ function add_part(part) {
// TODO - Work out how to add in category name + link... // TODO - Work out how to add in category name + link...
if (part.category){ if (part.category){
text += "category: " + part.category; text += '<a href="/part/category/' + part.category + '/">';
text += part.category_path;
text += '</a>';
} }
text += "</td>"; text += "</td>";

View File

@ -10,10 +10,8 @@
{% include "part/category_subcategories.html" with children=children %} {% include "part/category_subcategories.html" with children=children %}
{% endif %} {% endif %}
{% if parts.all|length > 0%} <h4>Parts</h4>
<h4>Top Level Parts</h4>
{% include "part/category_parts.html" with parts=parts %} {% include "part/category_parts.html" with parts=parts %}
{% endif %}
<div class='container-fluid'> <div class='container-fluid'>
<a href="{% url 'category-create' %}"> <a href="{% url 'category-create' %}">