mirror of
https://github.com/daniviga/django-ram.git
synced 2025-08-04 21:27:49 +02:00
Add consist app
This commit is contained in:
0
dcc/consist/__init__.py
Normal file
0
dcc/consist/__init__.py
Normal file
35
dcc/consist/admin.py
Normal file
35
dcc/consist/admin.py
Normal 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
6
dcc/consist/apps.py
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
from django.apps import AppConfig
|
||||||
|
|
||||||
|
|
||||||
|
class ConsistConfig(AppConfig):
|
||||||
|
default_auto_field = 'django.db.models.BigAutoField'
|
||||||
|
name = 'consist'
|
39
dcc/consist/migrations/0001_initial.py
Normal file
39
dcc/consist/migrations/0001_initial.py
Normal 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')),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
]
|
@@ -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),
|
||||||
|
),
|
||||||
|
]
|
18
dcc/consist/migrations/0003_consist_address.py
Normal file
18
dcc/consist/migrations/0003_consist_address.py
Normal 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),
|
||||||
|
),
|
||||||
|
]
|
0
dcc/consist/migrations/__init__.py
Normal file
0
dcc/consist/migrations/__init__.py
Normal file
53
dcc/consist/models.py
Normal file
53
dcc/consist/models.py
Normal 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
3
dcc/consist/tests.py
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
from django.test import TestCase
|
||||||
|
|
||||||
|
# Create your tests here.
|
3
dcc/consist/views.py
Normal file
3
dcc/consist/views.py
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
from django.shortcuts import render
|
||||||
|
|
||||||
|
# Create your views here.
|
@@ -43,10 +43,12 @@ INSTALLED_APPS = [
|
|||||||
'django_countries',
|
'django_countries',
|
||||||
'solo',
|
'solo',
|
||||||
'rest_framework',
|
'rest_framework',
|
||||||
|
'adminsortable2',
|
||||||
'dcc',
|
'dcc',
|
||||||
'driver',
|
'driver',
|
||||||
'metadata',
|
'metadata',
|
||||||
'roster',
|
'roster',
|
||||||
|
'consist',
|
||||||
]
|
]
|
||||||
|
|
||||||
MIDDLEWARE = [
|
MIDDLEWARE = [
|
||||||
|
@@ -1,6 +1,6 @@
|
|||||||
from django.contrib import admin
|
from django.contrib import admin
|
||||||
from roster.models import (
|
from roster.models import (
|
||||||
RollingStock, RollingStockImage, RollingStockDocument, Engine, Car,
|
RollingStockImage, RollingStockDocument, Engine, Car,
|
||||||
Equipment, Other)
|
Equipment, Other)
|
||||||
|
|
||||||
|
|
||||||
|
36
dcc/roster/migrations/0003_consistitem_consist.py
Normal file
36
dcc/roster/migrations/0003_consistitem_consist.py
Normal 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')),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
]
|
20
dcc/roster/migrations/0004_consistitem_consist.py
Normal file
20
dcc/roster/migrations/0004_consistitem_consist.py
Normal 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,
|
||||||
|
),
|
||||||
|
]
|
@@ -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',
|
||||||
|
),
|
||||||
|
]
|
@@ -37,9 +37,7 @@ class RollingStock(models.Model):
|
|||||||
epoch = models.CharField(max_length=32, blank=True)
|
epoch = models.CharField(max_length=32, blank=True)
|
||||||
production_year = models.SmallIntegerField(null=True, blank=True)
|
production_year = models.SmallIntegerField(null=True, blank=True)
|
||||||
purchase_date = models.DateField(null=True, blank=True)
|
purchase_date = models.DateField(null=True, blank=True)
|
||||||
|
|
||||||
notes = models.TextField(blank=True)
|
notes = models.TextField(blank=True)
|
||||||
|
|
||||||
creation_time = models.DateTimeField(auto_now_add=True)
|
creation_time = models.DateTimeField(auto_now_add=True)
|
||||||
updated_time = models.DateTimeField(auto_now=True)
|
updated_time = models.DateTimeField(auto_now=True)
|
||||||
|
|
||||||
|
@@ -5,6 +5,7 @@ djangorestframework
|
|||||||
django-solo
|
django-solo
|
||||||
django-countries
|
django-countries
|
||||||
django-health-check
|
django-health-check
|
||||||
|
django-admin-sortable2
|
||||||
# psycopg2-binary
|
# psycopg2-binary
|
||||||
# paho-mqtt
|
# paho-mqtt
|
||||||
# asyncio-mqtt
|
# asyncio-mqtt
|
||||||
|
Reference in New Issue
Block a user