mirror of
https://github.com/daniviga/django-ram.git
synced 2025-08-04 13:17:50 +02:00
Rename DCC project into RAM
RAM: Railroad Assets Manager
This commit is contained in:
0
ram/consist/__init__.py
Normal file
0
ram/consist/__init__.py
Normal file
49
ram/consist/admin.py
Normal file
49
ram/consist/admin.py
Normal file
@@ -0,0 +1,49 @@
|
||||
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", "type", "company", "era")
|
||||
|
||||
|
||||
@admin.register(Consist)
|
||||
class ConsistAdmin(admin.ModelAdmin):
|
||||
inlines = (ConsistItemInline,)
|
||||
readonly_fields = (
|
||||
"creation_time",
|
||||
"updated_time",
|
||||
)
|
||||
list_display = ("identifier", "company", "era")
|
||||
list_filter = list_display
|
||||
search_fields = list_display
|
||||
|
||||
fieldsets = (
|
||||
(
|
||||
None,
|
||||
{
|
||||
"fields": (
|
||||
"identifier",
|
||||
"consist_address",
|
||||
"company",
|
||||
"era",
|
||||
"notes",
|
||||
"tags",
|
||||
)
|
||||
},
|
||||
),
|
||||
(
|
||||
"Audit",
|
||||
{
|
||||
"classes": ("collapse",),
|
||||
"fields": (
|
||||
"creation_time",
|
||||
"updated_time",
|
||||
),
|
||||
},
|
||||
),
|
||||
)
|
6
ram/consist/apps.py
Normal file
6
ram/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"
|
44
ram/consist/migrations/0001_initial.py
Normal file
44
ram/consist/migrations/0001_initial.py
Normal file
@@ -0,0 +1,44 @@
|
||||
# Generated by Django 4.0.3 on 2022-04-07 09:25
|
||||
|
||||
from django.db import migrations, models
|
||||
import django.db.models.deletion
|
||||
import uuid
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
initial = True
|
||||
|
||||
dependencies = [
|
||||
('metadata', '0001_initial'),
|
||||
('roster', '0001_initial'),
|
||||
]
|
||||
|
||||
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)),
|
||||
('consist_address', models.SmallIntegerField(blank=True, default=None, null=True)),
|
||||
('era', 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')),
|
||||
('order', models.PositiveIntegerField(default=0)),
|
||||
('consist', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='consist_item', to='consist.consist')),
|
||||
('rolling_stock', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='roster.rollingstock')),
|
||||
],
|
||||
options={
|
||||
'ordering': ['order'],
|
||||
},
|
||||
),
|
||||
]
|
0
ram/consist/migrations/__init__.py
Normal file
0
ram/consist/migrations/__init__.py
Normal file
52
ram/consist/models.py
Normal file
52
ram/consist/models.py
Normal file
@@ -0,0 +1,52 @@
|
||||
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)
|
||||
consist_address = models.SmallIntegerField(
|
||||
default=None, null=True, blank=True
|
||||
)
|
||||
company = models.ForeignKey(
|
||||
Company, on_delete=models.CASCADE, null=True, 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)
|
||||
|
||||
def __str__(self):
|
||||
return "{0}".format(self.identifier)
|
||||
|
||||
|
||||
class ConsistItem(models.Model):
|
||||
consist = models.ForeignKey(
|
||||
Consist,
|
||||
on_delete=models.CASCADE,
|
||||
related_name="consist_item"
|
||||
)
|
||||
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)
|
||||
|
||||
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()
|
||||
|
||||
def era(self):
|
||||
return self.rolling_stock.era
|
24
ram/consist/serializers.py
Normal file
24
ram/consist/serializers.py
Normal file
@@ -0,0 +1,24 @@
|
||||
from rest_framework import serializers
|
||||
from consist.models import Consist, ConsistItem
|
||||
|
||||
from metadata.serializers import CompanySerializer, TagSerializer
|
||||
|
||||
# from roster.serializers import RollingStockSerializer
|
||||
|
||||
|
||||
class ConsistItemSerializer(serializers.ModelSerializer):
|
||||
# rolling_stock = RollingStockSerializer()
|
||||
|
||||
class Meta:
|
||||
model = ConsistItem
|
||||
fields = ("order", "rolling_stock")
|
||||
|
||||
|
||||
class ConsistSerializer(serializers.ModelSerializer):
|
||||
company = CompanySerializer()
|
||||
consist_item = ConsistItemSerializer(many=True)
|
||||
tags = TagSerializer(many=True)
|
||||
|
||||
class Meta:
|
||||
model = Consist
|
||||
fields = "__all__"
|
3
ram/consist/tests.py
Normal file
3
ram/consist/tests.py
Normal file
@@ -0,0 +1,3 @@
|
||||
from django.test import TestCase
|
||||
|
||||
# Create your tests here.
|
6
ram/consist/urls.py
Normal file
6
ram/consist/urls.py
Normal file
@@ -0,0 +1,6 @@
|
||||
from django.urls import path
|
||||
from consist.views import ConsistList
|
||||
|
||||
urlpatterns = [
|
||||
path("list", ConsistList.as_view()),
|
||||
]
|
15
ram/consist/views.py
Normal file
15
ram/consist/views.py
Normal file
@@ -0,0 +1,15 @@
|
||||
from rest_framework.generics import ListAPIView, RetrieveAPIView
|
||||
|
||||
from consist.models import Consist
|
||||
from consist.serializers import ConsistSerializer
|
||||
|
||||
|
||||
class ConsistList(ListAPIView):
|
||||
queryset = Consist.objects.all()
|
||||
serializer_class = ConsistSerializer
|
||||
|
||||
|
||||
class ConsistGet(RetrieveAPIView):
|
||||
queryset = Consist.objects.all()
|
||||
serializer_class = ConsistSerializer
|
||||
lookup_field = "uuid"
|
Reference in New Issue
Block a user