Add consist app

This commit is contained in:
2022-04-02 12:43:40 +02:00
parent 44b93bd5e8
commit 915bc13575
17 changed files with 266 additions and 3 deletions

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

35
dcc/consist/admin.py Normal file
View File

@@ -0,0 +1,35 @@
from django.contrib import admin
from adminsortable2.admin import SortableInlineAdminMixin
from consist.models import Consist, ConsistItem
class ConsistItemInline(SortableInlineAdminMixin, admin.TabularInline):
model = ConsistItem
min_num = 1
extra = 0
readonly_fields = ('address', 'company', 'epoch')
@admin.register(Consist)
class ConsistAdmin(admin.ModelAdmin):
inlines = (ConsistItemInline,)
readonly_fields = ('creation_time', 'updated_time',)
list_display = ('identifier', 'company', 'epoch')
list_filter = list_display
search_fields = list_display
fieldsets = (
(None, {
'fields': ('identifier',
'address',
'tags',
'company',
'epoch',
'notes')
}),
('Audit', {
'classes': ('collapse',),
'fields': ('creation_time', 'updated_time',)
}),
)

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

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

View File

@@ -0,0 +1,39 @@
# Generated by Django 4.0.2 on 2022-04-02 09:22
from django.db import migrations, models
import django.db.models.deletion
import uuid
class Migration(migrations.Migration):
initial = True
dependencies = [
('metadata', '0001_initial'),
('roster', '0005_remove_consistitem_consist_and_more'),
]
operations = [
migrations.CreateModel(
name='Consist',
fields=[
('uuid', models.UUIDField(default=uuid.uuid4, editable=False, primary_key=True, serialize=False)),
('identifier', models.CharField(max_length=128)),
('epoch', models.CharField(blank=True, max_length=32)),
('notes', models.TextField(blank=True)),
('creation_time', models.DateTimeField(auto_now_add=True)),
('updated_time', models.DateTimeField(auto_now=True)),
('company', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, to='metadata.company')),
('tags', models.ManyToManyField(blank=True, related_name='consist', to='metadata.Tag')),
],
),
migrations.CreateModel(
name='ConsistItem',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('consist', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='consist.consist')),
('rolling_stock', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='roster.rollingstock')),
],
),
]

View File

@@ -0,0 +1,22 @@
# Generated by Django 4.0.2 on 2022-04-02 09:25
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('consist', '0001_initial'),
]
operations = [
migrations.AlterModelOptions(
name='consistitem',
options={'ordering': ['order']},
),
migrations.AddField(
model_name='consistitem',
name='order',
field=models.PositiveIntegerField(default=0),
),
]

View File

@@ -0,0 +1,18 @@
# Generated by Django 4.0.2 on 2022-04-02 10:36
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('consist', '0002_alter_consistitem_options_consistitem_order'),
]
operations = [
migrations.AddField(
model_name='consist',
name='address',
field=models.SmallIntegerField(blank=True, default=None, null=True),
),
]

View File

53
dcc/consist/models.py Normal file
View File

@@ -0,0 +1,53 @@
from uuid import uuid4
from django.db import models
from metadata.models import Company, Tag
from roster.models import RollingStock
class Consist(models.Model):
uuid = models.UUIDField(
primary_key=True, default=uuid4,
editable=False)
identifier = models.CharField(max_length=128, unique=False)
tags = models.ManyToManyField(
Tag,
related_name='consist',
blank=True)
address = models.SmallIntegerField(default=None, null=True, blank=True)
company = models.ForeignKey(
Company, on_delete=models.CASCADE,
null=True, blank=True)
epoch = models.CharField(max_length=32, blank=True)
notes = models.TextField(blank=True)
creation_time = models.DateTimeField(auto_now_add=True)
updated_time = models.DateTimeField(auto_now=True)
def __str__(self):
return "{0}".format(self.identifier)
class ConsistItem(models.Model):
consist = models.ForeignKey(
Consist, on_delete=models.CASCADE)
rolling_stock = models.ForeignKey(
RollingStock, on_delete=models.CASCADE)
order = models.PositiveIntegerField(default=0, blank=False, null=False)
class Meta(object):
ordering = ['order']
def __str__(self):
return "{0}".format(self.rolling_stock.identifier)
# def type(self):
# return self.rolling_stock.type
def address(self):
return self.rolling_stock.address
def company(self):
return self.rolling_stock.company
def epoch(self):
return self.rolling_stock.epoch

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

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

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

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

View File

@@ -43,10 +43,12 @@ INSTALLED_APPS = [
'django_countries',
'solo',
'rest_framework',
'adminsortable2',
'dcc',
'driver',
'metadata',
'roster',
'consist',
]
MIDDLEWARE = [

View File

@@ -1,6 +1,6 @@
from django.contrib import admin
from roster.models import (
RollingStock, RollingStockImage, RollingStockDocument, Engine, Car,
RollingStockImage, RollingStockDocument, Engine, Car,
Equipment, Other)

View File

@@ -0,0 +1,36 @@
# Generated by Django 4.0.2 on 2022-04-02 09:09
from django.db import migrations, models
import django.db.models.deletion
import uuid
class Migration(migrations.Migration):
dependencies = [
('metadata', '0001_initial'),
('roster', '0002_alter_rollingstock_address'),
]
operations = [
migrations.CreateModel(
name='ConsistItem',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('rolling_stock', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='roster.rollingstock')),
],
),
migrations.CreateModel(
name='Consist',
fields=[
('uuid', models.UUIDField(default=uuid.uuid4, editable=False, primary_key=True, serialize=False)),
('identifier', models.CharField(max_length=128)),
('epoch', models.CharField(blank=True, max_length=32)),
('notes', models.TextField(blank=True)),
('creation_time', models.DateTimeField(auto_now_add=True)),
('updated_time', models.DateTimeField(auto_now=True)),
('company', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, to='metadata.company')),
('tags', models.ManyToManyField(blank=True, related_name='consist', to='metadata.Tag')),
],
),
]

View File

@@ -0,0 +1,20 @@
# Generated by Django 4.0.2 on 2022-04-02 09:13
from django.db import migrations, models
import django.db.models.deletion
class Migration(migrations.Migration):
dependencies = [
('roster', '0003_consistitem_consist'),
]
operations = [
migrations.AddField(
model_name='consistitem',
name='consist',
field=models.ForeignKey(default=None, on_delete=django.db.models.deletion.CASCADE, to='roster.consist'),
preserve_default=False,
),
]

View File

@@ -0,0 +1,27 @@
# Generated by Django 4.0.2 on 2022-04-02 09:21
from django.db import migrations
class Migration(migrations.Migration):
dependencies = [
('roster', '0004_consistitem_consist'),
]
operations = [
migrations.RemoveField(
model_name='consistitem',
name='consist',
),
migrations.RemoveField(
model_name='consistitem',
name='rolling_stock',
),
migrations.DeleteModel(
name='Consist',
),
migrations.DeleteModel(
name='ConsistItem',
),
]

View File

@@ -37,9 +37,7 @@ class RollingStock(models.Model):
epoch = models.CharField(max_length=32, blank=True)
production_year = models.SmallIntegerField(null=True, blank=True)
purchase_date = models.DateField(null=True, blank=True)
notes = models.TextField(blank=True)
creation_time = models.DateTimeField(auto_now_add=True)
updated_time = models.DateTimeField(auto_now=True)

View File

@@ -5,6 +5,7 @@ djangorestframework
django-solo
django-countries
django-health-check
django-admin-sortable2
# psycopg2-binary
# paho-mqtt
# asyncio-mqtt