mirror of
https://github.com/daniviga/django-ram.git
synced 2025-08-04 21:27:49 +02:00
Refactor roster and initial support for consists
This commit is contained in:
@@ -8,25 +8,25 @@ class ConsistItemInline(SortableInlineAdminMixin, admin.TabularInline):
|
||||
model = ConsistItem
|
||||
min_num = 1
|
||||
extra = 0
|
||||
readonly_fields = ('address', 'company', 'epoch')
|
||||
readonly_fields = ('address', 'type', 'company', 'era')
|
||||
|
||||
|
||||
@admin.register(Consist)
|
||||
class ConsistAdmin(admin.ModelAdmin):
|
||||
inlines = (ConsistItemInline,)
|
||||
readonly_fields = ('creation_time', 'updated_time',)
|
||||
list_display = ('identifier', 'company', 'epoch')
|
||||
list_display = ('identifier', 'company', 'era')
|
||||
list_filter = list_display
|
||||
search_fields = list_display
|
||||
|
||||
fieldsets = (
|
||||
(None, {
|
||||
'fields': ('identifier',
|
||||
'address',
|
||||
'tags',
|
||||
'consist_address',
|
||||
'company',
|
||||
'epoch',
|
||||
'notes')
|
||||
'era',
|
||||
'notes',
|
||||
'tags')
|
||||
}),
|
||||
('Audit', {
|
||||
'classes': ('collapse',),
|
||||
|
@@ -1,4 +1,4 @@
|
||||
# Generated by Django 4.0.2 on 2022-04-02 09:22
|
||||
# Generated by Django 4.0.2 on 2022-04-02 14:25
|
||||
|
||||
from django.db import migrations, models
|
||||
import django.db.models.deletion
|
||||
@@ -10,8 +10,8 @@ class Migration(migrations.Migration):
|
||||
initial = True
|
||||
|
||||
dependencies = [
|
||||
('roster', '0001_initial'),
|
||||
('metadata', '0001_initial'),
|
||||
('roster', '0005_remove_consistitem_consist_and_more'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
@@ -20,6 +20,7 @@ class Migration(migrations.Migration):
|
||||
fields=[
|
||||
('uuid', models.UUIDField(default=uuid.uuid4, editable=False, primary_key=True, serialize=False)),
|
||||
('identifier', models.CharField(max_length=128)),
|
||||
('address', models.SmallIntegerField(blank=True, default=None, null=True)),
|
||||
('epoch', models.CharField(blank=True, max_length=32)),
|
||||
('notes', models.TextField(blank=True)),
|
||||
('creation_time', models.DateTimeField(auto_now_add=True)),
|
||||
@@ -32,8 +33,12 @@ class Migration(migrations.Migration):
|
||||
name='ConsistItem',
|
||||
fields=[
|
||||
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
|
||||
('order', models.PositiveIntegerField(default=0)),
|
||||
('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')),
|
||||
],
|
||||
options={
|
||||
'ordering': ['order'],
|
||||
},
|
||||
),
|
||||
]
|
||||
|
@@ -1,22 +0,0 @@
|
||||
# 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),
|
||||
),
|
||||
]
|
@@ -0,0 +1,23 @@
|
||||
# Generated by Django 4.0.2 on 2022-04-02 16:18
|
||||
|
||||
from django.db import migrations
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('consist', '0001_initial'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.RenameField(
|
||||
model_name='consist',
|
||||
old_name='address',
|
||||
new_name='consist_address',
|
||||
),
|
||||
migrations.RenameField(
|
||||
model_name='consist',
|
||||
old_name='epoch',
|
||||
new_name='era',
|
||||
),
|
||||
]
|
@@ -1,18 +0,0 @@
|
||||
# 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),
|
||||
),
|
||||
]
|
@@ -14,11 +14,12 @@ class Consist(models.Model):
|
||||
Tag,
|
||||
related_name='consist',
|
||||
blank=True)
|
||||
address = models.SmallIntegerField(default=None, null=True, blank=True)
|
||||
consist_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)
|
||||
era = 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)
|
||||
@@ -38,16 +39,16 @@ class ConsistItem(models.Model):
|
||||
ordering = ['order']
|
||||
|
||||
def __str__(self):
|
||||
return "{0}".format(self.rolling_stock.identifier)
|
||||
return "{0}".format(self.rolling_stock)
|
||||
|
||||
# def type(self):
|
||||
# return self.rolling_stock.type
|
||||
def type(self):
|
||||
return self.rolling_stock.rolling_class.type
|
||||
|
||||
def address(self):
|
||||
return self.rolling_stock.address
|
||||
|
||||
def company(self):
|
||||
return self.rolling_stock.company
|
||||
return self.rolling_stock.company()
|
||||
|
||||
def epoch(self):
|
||||
return self.rolling_stock.epoch
|
||||
def era(self):
|
||||
return self.rolling_stock.era
|
||||
|
Reference in New Issue
Block a user