From 02033c2157a3cc239325b8dc1f9b56062f03c795 Mon Sep 17 00:00:00 2001 From: Oliver Walters Date: Tue, 14 May 2019 17:23:20 +1000 Subject: [PATCH] Add 'keywords' field to Part - Shows up in search results --- InvenTree/part/api.py | 1 + InvenTree/part/forms.py | 3 ++- .../part/migrations/0023_part_keywords.py | 18 ++++++++++++++++++ InvenTree/part/models.py | 5 ++++- InvenTree/part/serializers.py | 15 ++++++++------- InvenTree/part/templates/part/detail.html | 14 ++++++++++---- 6 files changed, 43 insertions(+), 13 deletions(-) create mode 100644 InvenTree/part/migrations/0023_part_keywords.py diff --git a/InvenTree/part/api.py b/InvenTree/part/api.py index 0a2bdbfef6..e671b49e4f 100644 --- a/InvenTree/part/api.py +++ b/InvenTree/part/api.py @@ -157,6 +157,7 @@ class PartList(generics.ListCreateAPIView): '$name', 'description', '$IPN', + 'keywords', ] diff --git a/InvenTree/part/forms.py b/InvenTree/part/forms.py index 580ed737a4..5dce37ac3b 100644 --- a/InvenTree/part/forms.py +++ b/InvenTree/part/forms.py @@ -92,9 +92,10 @@ class EditPartForm(HelperForm): 'confirm_creation', 'category', 'name', + 'IPN', 'variant', 'description', - 'IPN', + 'keywords', 'URL', 'default_location', 'default_supplier', diff --git a/InvenTree/part/migrations/0023_part_keywords.py b/InvenTree/part/migrations/0023_part_keywords.py new file mode 100644 index 0000000000..4752d80740 --- /dev/null +++ b/InvenTree/part/migrations/0023_part_keywords.py @@ -0,0 +1,18 @@ +# Generated by Django 2.2 on 2019-05-14 07:15 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('part', '0022_auto_20190512_1246'), + ] + + operations = [ + migrations.AddField( + model_name='part', + name='keywords', + field=models.CharField(blank=True, help_text='Part keywords to improve visibility in search results', max_length=250), + ), + ] diff --git a/InvenTree/part/models.py b/InvenTree/part/models.py index 5a609c0e59..db9e79224b 100644 --- a/InvenTree/part/models.py +++ b/InvenTree/part/models.py @@ -179,8 +179,9 @@ class Part(models.Model): Attributes: name: Brief name for this part variant: Optional variant number for this part - Must be unique for the part name - description: Longer form description of the part category: The PartCategory to which this part belongs + description: Longer form description of the part + keywords: Optional keywords for improving part search results IPN: Internal part number (optional) URL: Link to an external page with more information about this part (e.g. internal Wiki) image: Image of this part @@ -250,6 +251,8 @@ class Part(models.Model): description = models.CharField(max_length=250, blank=False, help_text='Part description') + keywords = models.CharField(max_length=250, blank=True, help_text='Part keywords to improve visibility in search results') + category = models.ForeignKey(PartCategory, related_name='parts', null=True, blank=True, on_delete=models.DO_NOTHING, diff --git a/InvenTree/part/serializers.py b/InvenTree/part/serializers.py index 957bfa5951..4d667eb356 100644 --- a/InvenTree/part/serializers.py +++ b/InvenTree/part/serializers.py @@ -62,15 +62,16 @@ class PartSerializer(serializers.ModelSerializer): fields = [ 'pk', 'url', # Link to the part detail page - 'full_name', - 'name', - 'variant', - 'image_url', - 'IPN', - 'URL', # Link to an external URL (optional) - 'description', 'category', 'category_name', + 'image_url', + 'full_name', + 'name', + 'IPN', + 'variant', + 'description', + 'keywords', + 'URL', 'total_stock', 'available_stock', 'units', diff --git a/InvenTree/part/templates/part/detail.html b/InvenTree/part/templates/part/detail.html index c0f823ce13..a7bad6cae4 100644 --- a/InvenTree/part/templates/part/detail.html +++ b/InvenTree/part/templates/part/detail.html @@ -35,16 +35,22 @@ Part name {{ part.full_name }} - - Description - {{ part.description }} - {% if part.IPN %} IPN {{ part.IPN }} {% endif %} + + Description + {{ part.description }} + + {% if part.keywords %} + + Keywords + {{ part.keywords }} + + {% endif %} {% if part.URL %} URL