Model updates, add FormFactor and Tags

This commit is contained in:
Johannes Schriewer 2020-12-16 01:26:42 +01:00
parent 9aa2612327
commit 1bebc74449
No known key found for this signature in database
GPG key ID: 85EB2BC0D45A0F86
11 changed files with 118 additions and 23 deletions

View file

@ -1,5 +1,7 @@
from .containers import WorkshopAdmin, AreaAdmin, BoxAdmin
from .distributor import DistributorAdmin
from .manufacturer import ManufacturerAdmin
from .layout import LayoutAdmin
from .item import ItemAdmin
from .containers import WorkshopAdmin, AreaAdmin, BoxAdmin
from .manufacturer import ManufacturerAdmin
from .form_factor import FormFactorAdmin
from .tag import TagAdmin

View file

@ -0,0 +1,12 @@
from django.contrib import admin
from inventory.models import FormFactor
class FormFactorAdmin(admin.ModelAdmin):
readonly_fields = ['created_at', 'changed_at']
search_fields = ['name', 'description']
list_display = ['name', 'description']
admin.site.register(FormFactor, FormFactorAdmin)

11
inventory/admin/tag.py Normal file
View file

@ -0,0 +1,11 @@
from django.contrib import admin
from inventory.models import Tag
class TagAdmin(admin.ModelAdmin):
readonly_fields = ['created_at', 'changed_at']
search_fields = ['name', 'description']
admin.site.register(Tag, TagAdmin)

View file

@ -1,7 +1,5 @@
# Generated by Django 3.0.4 on 2020-08-03 21:20
# Generated by Django 3.1.4 on 2020-12-16 00:13
import django.contrib.postgres.fields
import django.contrib.postgres.fields.jsonb
from django.db import migrations, models
import django.db.models.deletion
@ -29,8 +27,32 @@ class Migration(migrations.Migration):
('created_at', models.DateTimeField(auto_now_add=True)),
('changed_at', models.DateTimeField(auto_now=True)),
('web_link', models.URLField(blank=True, null=True)),
('search_link', models.URLField(blank=True, null=True, verbose_name='Use {} for search placeholder')),
('search_link', models.URLField(blank=True, help_text='Use {} for search placeholder', null=True)),
('phone', models.CharField(blank=True, max_length=128, null=True)),
('email', models.EmailField(blank=True, default=None, max_length=254, null=True)),
('icon', models.ImageField(blank=True, null=True, upload_to='')),
],
),
migrations.CreateModel(
name='Documentation',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('name', models.CharField(max_length=255, unique=True)),
('created_at', models.DateTimeField(auto_now_add=True)),
('changed_at', models.DateTimeField(auto_now=True)),
('file', models.FileField(upload_to='')),
],
),
migrations.CreateModel(
name='FormFactor',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('name', models.CharField(max_length=255, unique=True)),
('description', models.CharField(max_length=4096)),
('created_at', models.DateTimeField(auto_now_add=True)),
('changed_at', models.DateTimeField(auto_now=True)),
('icon', models.ImageField(blank=True, null=True, upload_to='')),
('datasheet', models.FileField(blank=True, null=True, upload_to='')),
],
),
migrations.CreateModel(
@ -41,7 +63,8 @@ class Migration(migrations.Migration):
('description', models.CharField(max_length=4096)),
('created_at', models.DateTimeField(auto_now_add=True)),
('changed_at', models.DateTimeField(auto_now=True)),
('data', django.contrib.postgres.fields.jsonb.JSONField()),
('data', models.JSONField()),
('template_name', models.CharField(blank=True, max_length=255, null=True)),
],
),
migrations.CreateModel(
@ -49,16 +72,27 @@ class Migration(migrations.Migration):
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('name', models.CharField(max_length=255, unique=True)),
('description', models.CharField(max_length=4096)),
('description', models.CharField(blank=True, max_length=4096)),
('created_at', models.DateTimeField(auto_now_add=True)),
('changed_at', models.DateTimeField(auto_now=True)),
('web_link', models.URLField(blank=True, null=True)),
('icon', models.ImageField(blank=True, null=True, upload_to='')),
],
),
migrations.CreateModel(
name='Tag',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('name', models.CharField(max_length=255, unique=True)),
('description', models.CharField(max_length=4096)),
('created_at', models.DateTimeField(auto_now_add=True)),
('changed_at', models.DateTimeField(auto_now=True)),
],
),
migrations.CreateModel(
name='Workshop',
fields=[
('container_ptr', models.OneToOneField(auto_created=True, on_delete=django.db.models.deletion.CASCADE, parent_link=True, primary_key=True, serialize=False, to='inventory.Container')),
('container_ptr', models.OneToOneField(auto_created=True, on_delete=django.db.models.deletion.CASCADE, parent_link=True, primary_key=True, serialize=False, to='inventory.container')),
('name', models.CharField(max_length=255, unique=True)),
('description', models.CharField(max_length=4096)),
('created_at', models.DateTimeField(auto_now_add=True)),
@ -71,18 +105,20 @@ class Migration(migrations.Migration):
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('index', models.PositiveIntegerField(verbose_name='Index of compartment in layout')),
('name', models.CharField(max_length=255, unique=True)),
('name', models.TextField(max_length=255)),
('description', models.CharField(max_length=4096)),
('created_at', models.DateTimeField(auto_now_add=True)),
('changed_at', models.DateTimeField(auto_now=True)),
('metadata', django.contrib.postgres.fields.jsonb.JSONField(verbose_name='Custom metadata, used by templates')),
('metadata', models.JSONField(blank=True, null=True, verbose_name='Custom metadata, used by templates')),
('distributor_item_no', models.CharField(blank=True, max_length=255, null=True)),
('price', models.DecimalField(blank=True, decimal_places=3, max_digits=7, null=True)),
('last_ordered_on', models.DateField(blank=True, null=True)),
('documentation', django.contrib.postgres.fields.ArrayField(base_field=models.FileField(upload_to=''), size=None)),
('container', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='item_related', to='inventory.Container')),
('distributor', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.PROTECT, to='inventory.Distributor')),
('manufacturer', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.PROTECT, to='inventory.Manufacturer')),
('container', models.ForeignKey(null=True, on_delete=django.db.models.deletion.CASCADE, related_name='item_related', to='inventory.container')),
('distributor', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.PROTECT, to='inventory.distributor')),
('documentation', models.ManyToManyField(blank=True, related_name='items', to='inventory.Documentation')),
('form_factor', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.PROTECT, to='inventory.formfactor')),
('manufacturer', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.PROTECT, to='inventory.manufacturer')),
('tags', models.ManyToManyField(blank=True, to='inventory.Tag')),
],
options={
'abstract': False,
@ -91,34 +127,34 @@ class Migration(migrations.Migration):
migrations.AddField(
model_name='container',
name='layout',
field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.PROTECT, to='inventory.Layout'),
field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.PROTECT, to='inventory.layout'),
),
migrations.CreateModel(
name='Box',
fields=[
('container_ptr', models.OneToOneField(auto_created=True, on_delete=django.db.models.deletion.CASCADE, parent_link=True, primary_key=True, serialize=False, to='inventory.Container')),
('container_ptr', models.OneToOneField(auto_created=True, on_delete=django.db.models.deletion.CASCADE, parent_link=True, primary_key=True, serialize=False, to='inventory.container')),
('index', models.PositiveIntegerField(verbose_name='Index of compartment in layout')),
('name', models.CharField(max_length=255, unique=True)),
('description', models.CharField(max_length=4096)),
('created_at', models.DateTimeField(auto_now_add=True)),
('changed_at', models.DateTimeField(auto_now=True)),
('container', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='box_related', to='inventory.Container')),
('container', models.ForeignKey(null=True, on_delete=django.db.models.deletion.CASCADE, related_name='box_related', to='inventory.container')),
],
options={
'abstract': False,
'verbose_name_plural': 'Boxes',
},
bases=('inventory.container', models.Model),
),
migrations.CreateModel(
name='Area',
fields=[
('container_ptr', models.OneToOneField(auto_created=True, on_delete=django.db.models.deletion.CASCADE, parent_link=True, primary_key=True, serialize=False, to='inventory.Container')),
('container_ptr', models.OneToOneField(auto_created=True, on_delete=django.db.models.deletion.CASCADE, parent_link=True, primary_key=True, serialize=False, to='inventory.container')),
('index', models.PositiveIntegerField(verbose_name='Index of compartment in layout')),
('name', models.CharField(max_length=255, unique=True)),
('description', models.CharField(max_length=4096)),
('created_at', models.DateTimeField(auto_now_add=True)),
('changed_at', models.DateTimeField(auto_now=True)),
('container', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='area_related', to='inventory.Container')),
('container', models.ForeignKey(null=True, on_delete=django.db.models.deletion.CASCADE, related_name='area_related', to='inventory.container')),
],
options={
'abstract': False,

View file

@ -1,9 +1,11 @@
from .area import Area
from .box import Box
from .distributor import Distributor
from .documentation import Documentation
from .form_factor import FormFactor
from .item import Item
from .layout import Layout
from .manufacturer import Manufacturer
from .tag import Tag
from .workshop import Workshop
from .container import Container, CanBeContained
from .documentation import Documentation

View file

@ -15,6 +15,9 @@ class Box(CanBeContained, Container):
@property
def template_name(self):
if self.layout.template_name:
template = 'inventory/box-' + self.layout.template_name + '.html'
else:
template = 'inventory/box-' + slugify(self.layout.name) + '.html'
try:
get_template(template)

View file

@ -2,6 +2,7 @@ from django.db import models
class Documentation(models.Model):
name = models.CharField(max_length=255, unique=True)
created_at = models.DateTimeField(auto_now_add=True)
changed_at = models.DateTimeField(auto_now=True)

View file

@ -0,0 +1,14 @@
from django.db import models
class FormFactor(models.Model):
name = models.CharField(max_length=255, unique=True)
description = models.CharField(max_length=4096)
created_at = models.DateTimeField(auto_now_add=True)
changed_at = models.DateTimeField(auto_now=True)
icon = models.ImageField(null=True, blank=True)
datasheet = models.FileField(null=True, blank=True)
def __str__(self):
return self.name

View file

@ -11,6 +11,7 @@ class Item(CanBeContained):
changed_at = models.DateTimeField(auto_now=True)
metadata = models.JSONField('Custom metadata, used by templates', blank=True, null=True)
form_factor = models.ForeignKey('inventory.FormFactor', null=True, blank=True, on_delete=models.PROTECT)
manufacturer = models.ForeignKey('inventory.Manufacturer', null=True, blank=True, on_delete=models.PROTECT)
distributor = models.ForeignKey('inventory.Distributor', null=True, blank=True, on_delete=models.PROTECT)
@ -18,6 +19,7 @@ class Item(CanBeContained):
price = models.DecimalField(decimal_places=3, max_digits=7, null=True, blank=True)
last_ordered_on = models.DateField(null=True, blank=True)
documentation = models.ManyToManyField('inventory.Documentation', related_name='items', blank=True)
tags = models.ManyToManyField('inventory.Tag', blank=True)
def __str__(self):
return self.name

View file

@ -7,6 +7,7 @@ class Layout(models.Model):
created_at = models.DateTimeField(auto_now_add=True)
changed_at = models.DateTimeField(auto_now=True)
data = models.JSONField()
template_name = models.CharField(max_length=255, null=True, blank=True)
def __str__(self):
return self.name

11
inventory/models/tag.py Normal file
View file

@ -0,0 +1,11 @@
from django.db import models
class Tag(models.Model):
name = models.CharField(max_length=255, unique=True)
description = models.CharField(max_length=4096)
created_at = models.DateTimeField(auto_now_add=True)
changed_at = models.DateTimeField(auto_now=True)
def __str__(self):
return self.name