Model restructuring
This commit is contained in:
parent
f85ed9efcc
commit
082afc26e6
7 changed files with 80 additions and 7 deletions
|
@ -5,9 +5,9 @@ from django.conf import settings
|
|||
from inventory.models import Item, Documentation
|
||||
|
||||
|
||||
class DocumentationInlineAdmin(admin.TabularInline):
|
||||
model = Documentation
|
||||
extra = 1
|
||||
class DocumentationAdmin(admin.ModelAdmin):
|
||||
list_display = ['file']
|
||||
search_fields = ['file']
|
||||
|
||||
|
||||
class ItemAdmin(admin.ModelAdmin):
|
||||
|
@ -16,10 +16,10 @@ class ItemAdmin(admin.ModelAdmin):
|
|||
list_filter = ['container']
|
||||
search_fields = ['name', 'description']
|
||||
readonly_fields = ['created_at', 'changed_at']
|
||||
inlines = [DocumentationInlineAdmin]
|
||||
|
||||
def view_on_site(self, obj):
|
||||
url = reverse('item-detail', kwargs={'pk': obj.id})
|
||||
return settings.SERVER_URL + url
|
||||
|
||||
admin.site.register(Item, ItemAdmin)
|
||||
admin.site.register(Documentation, DocumentationAdmin)
|
24
inventory/migrations/0005_auto_20200808_0135.py
Normal file
24
inventory/migrations/0005_auto_20200808_0135.py
Normal file
|
@ -0,0 +1,24 @@
|
|||
# Generated by Django 3.0.4 on 2020-08-07 23:35
|
||||
|
||||
from django.db import migrations, models
|
||||
import django.db.models.deletion
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('inventory', '0004_auto_20200804_0055'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AlterField(
|
||||
model_name='documentation',
|
||||
name='item',
|
||||
field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='documentation', to='inventory.Item'),
|
||||
),
|
||||
migrations.AlterField(
|
||||
model_name='item',
|
||||
name='name',
|
||||
field=models.TextField(max_length=255),
|
||||
),
|
||||
]
|
17
inventory/migrations/0006_remove_documentation_item.py
Normal file
17
inventory/migrations/0006_remove_documentation_item.py
Normal file
|
@ -0,0 +1,17 @@
|
|||
# Generated by Django 3.0.4 on 2020-08-07 23:57
|
||||
|
||||
from django.db import migrations
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('inventory', '0005_auto_20200808_0135'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.RemoveField(
|
||||
model_name='documentation',
|
||||
name='item',
|
||||
),
|
||||
]
|
18
inventory/migrations/0007_item_documentation.py
Normal file
18
inventory/migrations/0007_item_documentation.py
Normal file
|
@ -0,0 +1,18 @@
|
|||
# Generated by Django 3.0.4 on 2020-08-07 23:58
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('inventory', '0006_remove_documentation_item'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AddField(
|
||||
model_name='item',
|
||||
name='documentation',
|
||||
field=models.ManyToManyField(to='inventory.Documentation'),
|
||||
),
|
||||
]
|
|
@ -1,3 +1,5 @@
|
|||
from django.utils.text import slugify
|
||||
from django.template.loader import get_template, TemplateDoesNotExist
|
||||
from django.db import models
|
||||
from .container import CanBeContained, Container
|
||||
|
||||
|
@ -10,3 +12,12 @@ class Box(CanBeContained, Container):
|
|||
|
||||
class Meta:
|
||||
verbose_name_plural = 'Boxes'
|
||||
|
||||
@property
|
||||
def template_name(self):
|
||||
template = 'inventory/box-' + slugify(self.layout.name) + '.html'
|
||||
try:
|
||||
get_template(template)
|
||||
return template
|
||||
except TemplateDoesNotExist:
|
||||
return 'inventory/box-generic.html'
|
||||
|
|
|
@ -6,4 +6,6 @@ class Documentation(models.Model):
|
|||
changed_at = models.DateTimeField(auto_now=True)
|
||||
|
||||
file = models.FileField()
|
||||
item = models.ForeignKey('inventory.Item', on_delete=models.CASCADE, related_name='documentation')
|
||||
|
||||
def __str__(self):
|
||||
return self.file.name
|
|
@ -5,7 +5,7 @@ from .container import CanBeContained
|
|||
|
||||
|
||||
class Item(CanBeContained):
|
||||
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)
|
||||
|
@ -17,6 +17,7 @@ class Item(CanBeContained):
|
|||
distributor_item_no = models.CharField(max_length=255, null=True, blank=True)
|
||||
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')
|
||||
|
||||
def __str__(self):
|
||||
return self.name
|
Loading…
Reference in a new issue