Simplify part model

- Remove 'varian't or ''revision' field
- Part name must be unique across database
This commit is contained in:
Oliver Walters 2019-05-26 12:16:57 +10:00
parent 1312148721
commit 91a5a7f051
7 changed files with 56 additions and 20 deletions

View File

@ -92,7 +92,6 @@ class EditPartForm(HelperForm):
'category', 'category',
'name', 'name',
'IPN', 'IPN',
'variant',
'is_template', 'is_template',
'variant_of', 'variant_of',
'description', 'description',

View File

@ -0,0 +1,26 @@
# Generated by Django 2.2 on 2019-05-26 01:19
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('part', '0004_auto_20190525_2356'),
]
operations = [
migrations.AddField(
model_name='part',
name='revision',
field=models.CharField(blank=True, help_text='Part rerevision code', max_length=32),
),
migrations.AlterUniqueTogether(
name='part',
unique_together={('name', 'revision')},
),
migrations.RemoveField(
model_name='part',
name='variant',
),
]

View File

@ -0,0 +1,27 @@
# Generated by Django 2.2 on 2019-05-26 02:15
import InvenTree.validators
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('part', '0005_auto_20190526_1119'),
]
operations = [
migrations.AlterField(
model_name='part',
name='name',
field=models.CharField(help_text='Part name (must be unique)', max_length=100, unique=True, validators=[InvenTree.validators.validate_part_name]),
),
migrations.AlterUniqueTogether(
name='part',
unique_together=set(),
),
migrations.RemoveField(
model_name='part',
name='revision',
),
]

View File

@ -162,6 +162,7 @@ def match_part_names(match, threshold=80, reverse=True, compare_length=False):
if compare_length: if compare_length:
# Also employ primitive length comparison # Also employ primitive length comparison
# TODO - Improve this somewhat...
l_min = min(len(match), len(compare)) l_min = min(len(match), len(compare))
l_max = max(len(match), len(compare)) l_max = max(len(match), len(compare))
@ -211,9 +212,6 @@ class Part(models.Model):
class Meta: class Meta:
verbose_name = "Part" verbose_name = "Part"
verbose_name_plural = "Parts" verbose_name_plural = "Parts"
unique_together = [
('name', 'variant')
]
def __str__(self): def __str__(self):
return "{n} - {d}".format(n=self.full_name, d=self.description) return "{n} - {d}".format(n=self.full_name, d=self.description)
@ -236,9 +234,6 @@ class Part(models.Model):
elements.append(self.name) elements.append(self.name)
if self.variant:
elements.append(self.variant)
return ' | '.join(elements) return ' | '.join(elements)
def get_absolute_url(self): def get_absolute_url(self):
@ -262,12 +257,11 @@ class Part(models.Model):
'variant_of': _("Part cannot be a variant of another part if it is already a template"), 'variant_of': _("Part cannot be a variant of another part if it is already a template"),
}) })
name = models.CharField(max_length=100, blank=False, help_text='Part name', name = models.CharField(max_length=100, blank=False, unique=True,
help_text='Part name (must be unique)',
validators=[validators.validate_part_name] validators=[validators.validate_part_name]
) )
variant = models.CharField(max_length=32, blank=True, help_text='Part variant or revision code')
is_template = models.BooleanField(default=False, help_text='Is this part a template part?') is_template = models.BooleanField(default=False, help_text='Is this part a template part?')
variant_of = models.ForeignKey('part.Part', related_name='variants', variant_of = models.ForeignKey('part.Part', related_name='variants',

View File

@ -87,7 +87,6 @@ class PartSerializer(serializers.ModelSerializer):
'IPN', 'IPN',
'is_template', 'is_template',
'variant_of', 'variant_of',
'variant',
'description', 'description',
'keywords', 'keywords',
'URL', 'URL',

View File

@ -42,12 +42,6 @@
<td>{{ part.IPN }}</td> <td>{{ part.IPN }}</td>
</tr> </tr>
{% endif %} {% endif %}
{% if part.variant %}
<tr>
<td><b>Variant</b></td>
<td>{{ part.variant }}</td>
</tr>
{% endif %}
<tr> <tr>
<td><b>Description</b></td> <td><b>Description</b></td>
<td>{{ part.description }}</td> <td>{{ part.description }}</td>

View File

@ -38,9 +38,6 @@
<h4> <h4>
{{ part.full_name }} {{ part.full_name }}
</h4> </h4>
{% if part.variant %}
<p>Variant: {{ part.variant }}</p>
{% endif %}
<p><i>{{ part.description }}</i></p> <p><i>{{ part.description }}</i></p>
<p> <p>
<div class='btn-group'> <div class='btn-group'>