Initial commit

This commit is contained in:
2021-12-16 15:41:07 +01:00
parent 2adb3607d5
commit c5b8a75f3b
29 changed files with 626 additions and 0 deletions

0
dcc/roster/__init__.py Normal file
View File

33
dcc/roster/admin.py Normal file
View File

@@ -0,0 +1,33 @@
from django.contrib import admin
from roster.models import Cab, Decoder, Manufacturer
@admin.register(Cab)
class CabAdmin(admin.ModelAdmin):
readonly_fields = ('image_thumbnail', 'creation_time', 'updated_time',)
list_display = ('identifier', 'manufacturer', 'address')
list_filter = list_display
search_fields = list_display
fieldsets = (
(None, {
'fields': ('identifier',
'address',
'manufacturer',
'decoder',
'epoch',
'production_year',
'purchase_date',
'image',
'image_thumbnail',
'notes')
}),
('Audit', {
'classes': ('collapse',),
'fields': ('creation_time', 'updated_time',)
}),
)
admin.site.register(Decoder)
admin.site.register(Manufacturer)

6
dcc/roster/apps.py Normal file
View File

@@ -0,0 +1,6 @@
from django.apps import AppConfig
class RosterConfig(AppConfig):
default_auto_field = 'django.db.models.BigAutoField'
name = 'roster'

View File

@@ -0,0 +1,37 @@
# Generated by Django 4.0 on 2021-12-15 22:16
from django.db import migrations, models
import django.db.models.deletion
import uuid
class Migration(migrations.Migration):
initial = True
dependencies = [
]
operations = [
migrations.CreateModel(
name='Manufacturer',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('name', models.CharField(max_length=128, unique=True)),
],
),
migrations.CreateModel(
name='Cab',
fields=[
('uuid', models.UUIDField(default=uuid.uuid4, editable=False, primary_key=True, serialize=False)),
('identifier', models.CharField(max_length=128)),
('address', models.SmallIntegerField(default=3)),
('creation_time', models.DateTimeField(auto_now_add=True)),
('updated_time', models.DateTimeField(auto_now=True)),
('manufacturer', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='roster.manufacturer')),
],
options={
'ordering': ['address', 'identifier'],
},
),
]

View File

@@ -0,0 +1,28 @@
# Generated by Django 4.0 on 2021-12-15 22:24
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('roster', '0001_initial'),
]
operations = [
migrations.AddField(
model_name='cab',
name='notes',
field=models.TextField(blank=True),
),
migrations.AddField(
model_name='cab',
name='production_date',
field=models.SmallIntegerField(null=True),
),
migrations.AddField(
model_name='cab',
name='production_year',
field=models.SmallIntegerField(null=True),
),
]

View File

@@ -0,0 +1,22 @@
# Generated by Django 4.0 on 2021-12-15 22:27
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('roster', '0002_cab_notes_cab_production_date_cab_production_year'),
]
operations = [
migrations.RemoveField(
model_name='cab',
name='production_date',
),
migrations.AddField(
model_name='cab',
name='purchase_date',
field=models.DateField(null=True),
),
]

View File

@@ -0,0 +1,29 @@
# Generated by Django 4.0 on 2021-12-15 22:28
from django.db import migrations, models
import django.db.models.deletion
class Migration(migrations.Migration):
dependencies = [
('roster', '0003_remove_cab_production_date_cab_purchase_date'),
]
operations = [
migrations.AlterField(
model_name='cab',
name='manufacturer',
field=models.ForeignKey(null=True, on_delete=django.db.models.deletion.CASCADE, to='roster.manufacturer'),
),
migrations.AlterField(
model_name='cab',
name='production_year',
field=models.SmallIntegerField(blank=True, null=True),
),
migrations.AlterField(
model_name='cab',
name='purchase_date',
field=models.DateField(blank=True, null=True),
),
]

View File

@@ -0,0 +1,19 @@
# Generated by Django 4.0 on 2021-12-15 22:29
from django.db import migrations, models
import django.db.models.deletion
class Migration(migrations.Migration):
dependencies = [
('roster', '0004_alter_cab_manufacturer_alter_cab_production_year_and_more'),
]
operations = [
migrations.AlterField(
model_name='cab',
name='manufacturer',
field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, to='roster.manufacturer'),
),
]

View File

@@ -0,0 +1,18 @@
# Generated by Django 4.0 on 2021-12-15 22:32
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('roster', '0005_alter_cab_manufacturer'),
]
operations = [
migrations.AddField(
model_name='cab',
name='image',
field=models.ImageField(blank=True, upload_to=''),
),
]

View File

@@ -0,0 +1,18 @@
# Generated by Django 4.0 on 2021-12-15 22:43
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('roster', '0006_cab_image'),
]
operations = [
migrations.AlterField(
model_name='cab',
name='image',
field=models.ImageField(blank=True, null=True, upload_to='images/'),
),
]

View File

@@ -0,0 +1,18 @@
# Generated by Django 4.0 on 2021-12-15 23:05
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('roster', '0007_alter_cab_image'),
]
operations = [
migrations.AddField(
model_name='cab',
name='epoch',
field=models.CharField(blank=True, max_length=32),
),
]

View File

@@ -0,0 +1,29 @@
# Generated by Django 4.0 on 2021-12-16 09:11
from django.db import migrations, models
import django.db.models.deletion
class Migration(migrations.Migration):
dependencies = [
('roster', '0008_cab_epoch'),
]
operations = [
migrations.AddField(
model_name='cab',
name='decoder_manufacturer',
field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, related_name='%(class)s_decoder', to='roster.manufacturer'),
),
migrations.AddField(
model_name='cab',
name='decoder_model',
field=models.CharField(blank=True, max_length=128),
),
migrations.AlterField(
model_name='cab',
name='manufacturer',
field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, related_name='%(class)s_manufacturer', to='roster.manufacturer'),
),
]

View File

@@ -0,0 +1,31 @@
# Generated by Django 4.0 on 2021-12-16 09:15
from django.db import migrations, models
import django.db.models.deletion
class Migration(migrations.Migration):
dependencies = [
('roster', '0009_cab_decoder_manufacturer_cab_decoder_model_and_more'),
]
operations = [
migrations.RemoveField(
model_name='cab',
name='decoder_manufacturer',
),
migrations.AlterField(
model_name='cab',
name='manufacturer',
field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, to='roster.manufacturer'),
),
migrations.CreateModel(
name='Decoder',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('name', models.CharField(max_length=128, unique=True)),
('manufacturer', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='roster.manufacturer')),
],
),
]

View File

@@ -0,0 +1,23 @@
# Generated by Django 4.0 on 2021-12-16 09:18
from django.db import migrations, models
import django.db.models.deletion
class Migration(migrations.Migration):
dependencies = [
('roster', '0010_remove_cab_decoder_manufacturer_and_more'),
]
operations = [
migrations.RemoveField(
model_name='cab',
name='decoder_model',
),
migrations.AddField(
model_name='cab',
name='decoder',
field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, to='roster.decoder'),
),
]

View File

82
dcc/roster/models.py Normal file
View File

@@ -0,0 +1,82 @@
from uuid import uuid4
from django.db import models
# from django.core.files.storage import FileSystemStorage
# from django.dispatch import receiver
from dcc.utils import get_image_preview
# class OverwriteMixin(FileSystemStorage):
# def get_available_name(self, name, max_length):
# self.delete(name)
# return name
class Manufacturer(models.Model):
name = models.CharField(max_length=128, unique=True)
def __str__(self):
return self.name
class Company(models.Model):
name = models.CharField(max_length=128, unique=True)
country = models.CharField(max_length=128, unique=True)
def __str__(self):
return self.name
class Decoder(models.Model):
name = models.CharField(max_length=128, unique=True)
manufacturer = models.ForeignKey(
Manufacturer,
on_delete=models.CASCADE)
def __str__(self):
return "{0} - {1}".format(self.manufacturer, self.name)
class Cab(models.Model):
uuid = models.UUIDField(
primary_key=True, default=uuid4,
editable=False)
identifier = models.CharField(max_length=128, unique=False)
address = models.SmallIntegerField(default=3)
manufacturer = models.ForeignKey(
Manufacturer, on_delete=models.CASCADE,
null=True, blank=True)
decoder = models.ForeignKey(
Decoder, on_delete=models.CASCADE,
null=True, blank=True)
epoch = models.CharField(max_length=32, blank=True)
production_year = models.SmallIntegerField(null=True, blank=True)
purchase_date = models.DateField(null=True, blank=True)
image = models.ImageField(
upload_to='images/',
null=True,
blank=True)
notes = models.TextField(blank=True)
creation_time = models.DateTimeField(auto_now_add=True)
updated_time = models.DateTimeField(auto_now=True)
class Meta:
ordering = ['address', 'identifier']
def __str__(self):
return "{0} {1}".format(self.manufacturer, self.identifier)
def image_thumbnail(self):
return get_image_preview(self.image.url)
image_thumbnail.short_description = "Preview"
# @receiver(models.signals.post_delete, sender=Cab)
# def post_save_image(sender, instance, *args, **kwargs):
# try:
# instance.image.delete(save=False)
# except Exception:
# pass

3
dcc/roster/tests.py Normal file
View File

@@ -0,0 +1,3 @@
from django.test import TestCase
# Create your tests here.

3
dcc/roster/views.py Normal file
View File

@@ -0,0 +1,3 @@
from django.shortcuts import render
# Create your views here.