mirror of
https://github.com/daniviga/django-ram.git
synced 2025-08-05 05:37:50 +02:00
Run black
This commit is contained in:
@@ -1,12 +1,16 @@
|
||||
from django.contrib import admin
|
||||
from roster.models import (
|
||||
RollingClass, RollingStock, RollingStockImage, RollingStockDocument)
|
||||
RollingClass,
|
||||
RollingStock,
|
||||
RollingStockImage,
|
||||
RollingStockDocument,
|
||||
)
|
||||
|
||||
|
||||
@admin.register(RollingClass)
|
||||
class RollingClass(admin.ModelAdmin):
|
||||
list_display = ('__str__', 'type', 'company')
|
||||
list_filter = ('company', 'type__category', 'type')
|
||||
list_display = ("__str__", "type", "company")
|
||||
list_filter = ("company", "type__category", "type")
|
||||
search_fields = list_display
|
||||
|
||||
|
||||
@@ -20,38 +24,58 @@ class RollingStockImageInline(admin.TabularInline):
|
||||
model = RollingStockImage
|
||||
min_num = 0
|
||||
extra = 0
|
||||
readonly_fields = ('image_thumbnail',)
|
||||
readonly_fields = ("image_thumbnail",)
|
||||
|
||||
|
||||
@admin.register(RollingStock)
|
||||
class RollingStockAdmin(admin.ModelAdmin):
|
||||
inlines = (RollingStockImageInline, RollingStockDocInline)
|
||||
readonly_fields = ('creation_time', 'updated_time')
|
||||
readonly_fields = ("creation_time", "updated_time")
|
||||
list_display = (
|
||||
'__str__', 'address', 'manufacturer',
|
||||
'scale', 'sku', 'company', 'country')
|
||||
"__str__",
|
||||
"address",
|
||||
"manufacturer",
|
||||
"scale",
|
||||
"sku",
|
||||
"company",
|
||||
"country",
|
||||
)
|
||||
list_filter = (
|
||||
'rolling_class__type__category', 'rolling_class__type',
|
||||
'scale', 'manufacturer')
|
||||
"rolling_class__type__category",
|
||||
"rolling_class__type",
|
||||
"scale",
|
||||
"manufacturer",
|
||||
)
|
||||
search_fields = list_display
|
||||
|
||||
fieldsets = (
|
||||
(None, {
|
||||
'fields': ('rolling_class',
|
||||
'road_number',
|
||||
'manufacturer',
|
||||
'scale',
|
||||
'sku',
|
||||
'decoder',
|
||||
'address',
|
||||
'era',
|
||||
'production_year',
|
||||
'purchase_date',
|
||||
'notes',
|
||||
'tags')
|
||||
}),
|
||||
('Audit', {
|
||||
'classes': ('collapse',),
|
||||
'fields': ('creation_time', 'updated_time',)
|
||||
}),
|
||||
(
|
||||
None,
|
||||
{
|
||||
"fields": (
|
||||
"rolling_class",
|
||||
"road_number",
|
||||
"manufacturer",
|
||||
"scale",
|
||||
"sku",
|
||||
"decoder",
|
||||
"address",
|
||||
"era",
|
||||
"production_year",
|
||||
"purchase_date",
|
||||
"notes",
|
||||
"tags",
|
||||
)
|
||||
},
|
||||
),
|
||||
(
|
||||
"Audit",
|
||||
{
|
||||
"classes": ("collapse",),
|
||||
"fields": (
|
||||
"creation_time",
|
||||
"updated_time",
|
||||
),
|
||||
},
|
||||
),
|
||||
)
|
||||
|
@@ -2,5 +2,5 @@ from django.apps import AppConfig
|
||||
|
||||
|
||||
class RosterConfig(AppConfig):
|
||||
default_auto_field = 'django.db.models.BigAutoField'
|
||||
name = 'roster'
|
||||
default_auto_field = "django.db.models.BigAutoField"
|
||||
name = "roster"
|
||||
|
@@ -2,12 +2,19 @@ import os
|
||||
from uuid import uuid4
|
||||
from django.db import models
|
||||
from django.urls import reverse
|
||||
|
||||
# from django.core.files.storage import FileSystemStorage
|
||||
# from django.dispatch import receiver
|
||||
|
||||
from dcc.utils import get_image_preview
|
||||
from metadata.models import (
|
||||
Scale, Manufacturer, Decoder, Company, Tag, RollingStockType)
|
||||
Scale,
|
||||
Manufacturer,
|
||||
Decoder,
|
||||
Company,
|
||||
Tag,
|
||||
RollingStockType,
|
||||
)
|
||||
|
||||
# class OverwriteMixin(FileSystemStorage):
|
||||
# def get_available_name(self, name, max_length):
|
||||
@@ -18,15 +25,15 @@ from metadata.models import (
|
||||
class RollingClass(models.Model):
|
||||
identifier = models.CharField(max_length=128, unique=False)
|
||||
type = models.ForeignKey(
|
||||
RollingStockType, on_delete=models.CASCADE,
|
||||
null=True, blank=True)
|
||||
RollingStockType, on_delete=models.CASCADE, null=True, blank=True
|
||||
)
|
||||
description = models.CharField(max_length=256, blank=True)
|
||||
company = models.ForeignKey(
|
||||
Company, on_delete=models.CASCADE,
|
||||
null=True, blank=True)
|
||||
Company, on_delete=models.CASCADE, null=True, blank=True
|
||||
)
|
||||
|
||||
class Meta:
|
||||
ordering = ['company', 'identifier']
|
||||
ordering = ["company", "identifier"]
|
||||
verbose_name = "Class"
|
||||
verbose_name_plural = "Classes"
|
||||
|
||||
@@ -35,37 +42,36 @@ class RollingClass(models.Model):
|
||||
|
||||
|
||||
class RollingStock(models.Model):
|
||||
uuid = models.UUIDField(
|
||||
primary_key=True, default=uuid4,
|
||||
editable=False)
|
||||
uuid = models.UUIDField(primary_key=True, default=uuid4, editable=False)
|
||||
rolling_class = models.ForeignKey(
|
||||
RollingClass, on_delete=models.CASCADE,
|
||||
null=False, blank=False,
|
||||
verbose_name="Class")
|
||||
RollingClass,
|
||||
on_delete=models.CASCADE,
|
||||
null=False,
|
||||
blank=False,
|
||||
verbose_name="Class",
|
||||
)
|
||||
road_number = models.CharField(max_length=128, unique=False)
|
||||
manufacturer = models.ForeignKey(
|
||||
Manufacturer, on_delete=models.CASCADE,
|
||||
null=True, blank=True)
|
||||
scale = models.ForeignKey(
|
||||
Scale, on_delete=models.CASCADE)
|
||||
Manufacturer, on_delete=models.CASCADE, null=True, blank=True
|
||||
)
|
||||
scale = models.ForeignKey(Scale, on_delete=models.CASCADE)
|
||||
sku = models.CharField(max_length=32, blank=True)
|
||||
decoder = models.ForeignKey(
|
||||
Decoder, on_delete=models.CASCADE,
|
||||
null=True, blank=True)
|
||||
Decoder, on_delete=models.CASCADE, null=True, blank=True
|
||||
)
|
||||
address = models.SmallIntegerField(default=None, null=True, blank=True)
|
||||
era = 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)
|
||||
tags = models.ManyToManyField(
|
||||
Tag,
|
||||
related_name='rolling_stock',
|
||||
blank=True)
|
||||
Tag, related_name="rolling_stock", blank=True
|
||||
)
|
||||
creation_time = models.DateTimeField(auto_now_add=True)
|
||||
updated_time = models.DateTimeField(auto_now=True)
|
||||
|
||||
class Meta:
|
||||
ordering = ['rolling_class', 'road_number']
|
||||
ordering = ["rolling_class", "road_number"]
|
||||
verbose_name_plural = "Rolling stock"
|
||||
|
||||
def __str__(self):
|
||||
@@ -79,16 +85,12 @@ class RollingStock(models.Model):
|
||||
|
||||
|
||||
class RollingStockDocument(models.Model):
|
||||
rolling_stock = models.ForeignKey(
|
||||
RollingStock, on_delete=models.CASCADE)
|
||||
rolling_stock = models.ForeignKey(RollingStock, on_delete=models.CASCADE)
|
||||
description = models.CharField(max_length=128, blank=True)
|
||||
file = models.FileField(
|
||||
upload_to='files/',
|
||||
null=True,
|
||||
blank=True)
|
||||
file = models.FileField(upload_to="files/", null=True, blank=True)
|
||||
|
||||
class Meta(object):
|
||||
unique_together = ('rolling_stock', 'file')
|
||||
unique_together = ("rolling_stock", "file")
|
||||
|
||||
def __str__(self):
|
||||
return "{0}".format(os.path.basename(self.file.name))
|
||||
@@ -96,23 +98,21 @@ class RollingStockDocument(models.Model):
|
||||
|
||||
|
||||
class RollingStockImage(models.Model):
|
||||
rolling_stock = models.ForeignKey(
|
||||
RollingStock, on_delete=models.CASCADE)
|
||||
image = models.ImageField(
|
||||
upload_to='images/',
|
||||
null=True,
|
||||
blank=True)
|
||||
rolling_stock = models.ForeignKey(RollingStock, on_delete=models.CASCADE)
|
||||
image = models.ImageField(upload_to="images/", null=True, blank=True)
|
||||
|
||||
def image_thumbnail(self):
|
||||
return get_image_preview(self.image.url)
|
||||
|
||||
image_thumbnail.short_description = "Preview"
|
||||
|
||||
class Meta(object):
|
||||
unique_together = ('rolling_stock', 'image')
|
||||
unique_together = ("rolling_stock", "image")
|
||||
|
||||
def __str__(self):
|
||||
return "{0}".format(os.path.basename(self.image.name))
|
||||
|
||||
|
||||
# @receiver(models.signals.post_delete, sender=Cab)
|
||||
# def post_save_image(sender, instance, *args, **kwargs):
|
||||
# try:
|
||||
|
@@ -1,8 +1,13 @@
|
||||
from rest_framework import serializers
|
||||
from roster.models import RollingClass, RollingStock
|
||||
from metadata.serializers import (
|
||||
RollingStockTypeSerializer, ManufacturerSerializer, ScaleSerializer,
|
||||
CompanySerializer, DecoderSerializer, TagSerializer)
|
||||
RollingStockTypeSerializer,
|
||||
ManufacturerSerializer,
|
||||
ScaleSerializer,
|
||||
CompanySerializer,
|
||||
DecoderSerializer,
|
||||
TagSerializer,
|
||||
)
|
||||
|
||||
|
||||
class RollingClassSerializer(serializers.ModelSerializer):
|
||||
|
@@ -1,10 +1,9 @@
|
||||
from django.urls import path
|
||||
from roster.views import (
|
||||
RosterList, RosterGet, RosterAddress, RosterIdentifier)
|
||||
from roster.views import RosterList, RosterGet, RosterAddress, RosterIdentifier
|
||||
|
||||
urlpatterns = [
|
||||
path('list', RosterList.as_view()),
|
||||
path('get/<str:uuid>', RosterGet.as_view()),
|
||||
path('address/<int:address>', RosterAddress.as_view()),
|
||||
path('identifier/<str:identifier>', RosterIdentifier.as_view()),
|
||||
path("list", RosterList.as_view()),
|
||||
path("get/<str:uuid>", RosterGet.as_view()),
|
||||
path("address/<int:address>", RosterAddress.as_view()),
|
||||
path("identifier/<str:identifier>", RosterIdentifier.as_view()),
|
||||
]
|
||||
|
@@ -12,16 +12,16 @@ class RosterList(ListAPIView):
|
||||
class RosterGet(RetrieveAPIView):
|
||||
queryset = RollingStock.objects.all()
|
||||
serializer_class = RollingStockSerializer
|
||||
lookup_field = 'uuid'
|
||||
lookup_field = "uuid"
|
||||
|
||||
|
||||
class RosterAddress(ListAPIView):
|
||||
queryset = RollingStock.objects.all()
|
||||
serializer_class = RollingStockSerializer
|
||||
lookup_field = 'address'
|
||||
lookup_field = "address"
|
||||
|
||||
|
||||
class RosterIdentifier(RetrieveAPIView):
|
||||
queryset = RollingStock.objects.all()
|
||||
serializer_class = RollingStockSerializer
|
||||
lookup_field = 'identifier'
|
||||
lookup_field = "identifier"
|
||||
|
Reference in New Issue
Block a user