2
0
mirror of https://github.com/inventree/InvenTree.git synced 2025-06-19 21:45:39 +00:00

Add 'has_variants' and 'variant_of' field for Part

- StockItem cannot point to a part which is a template part
This commit is contained in:
Oliver Walters
2019-05-25 22:27:36 +10:00
parent 1ac1c472c7
commit 1a2fb9e170
4 changed files with 68 additions and 1 deletions

View File

@ -0,0 +1,24 @@
# Generated by Django 2.2 on 2019-05-25 12:26
from django.db import migrations, models
import django.db.models.deletion
class Migration(migrations.Migration):
dependencies = [
('part', '0002_auto_20190520_2204'),
]
operations = [
migrations.AddField(
model_name='part',
name='has_variants',
field=models.BooleanField(default=False, help_text='Is this part a template part?'),
),
migrations.AddField(
model_name='part',
name='variant_of',
field=models.ForeignKey(blank=True, help_text='Is this part a variant of another part?', limit_choices_to={'active': True, 'has_variants': True}, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='variants', to='part.Part'),
),
]

View File

@ -192,6 +192,7 @@ class Part(models.Model):
description: Longer form description of the part
keywords: Optional keywords for improving part search results
IPN: Internal part number (optional)
has_variants: If True, this part is a 'template' part and cannot be instantiated as a StockItem
URL: Link to an external page with more information about this part (e.g. internal Wiki)
image: Image of this part
default_location: Where the item is normally stored (may be null)
@ -258,6 +259,17 @@ class Part(models.Model):
variant = models.CharField(max_length=32, blank=True, help_text='Part variant or revision code')
has_variants = models.BooleanField(default=False, help_text='Is this part a template part?')
variant_of = models.ForeignKey('part.Part', related_name='variants',
null=True, blank=True,
limit_choices_to={
'has_variants': True,
'active': True,
},
on_delete=models.SET_NULL,
help_text='Is this part a variant of another part?')
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')