mirror of
https://github.com/daniviga/django-ram.git
synced 2025-08-04 13:17:50 +02:00
Fix the API
This commit is contained in:
@@ -152,6 +152,7 @@ DECODER_INTERFACES = [
|
||||
ROLLING_STOCK_TYPES = [
|
||||
("engine", "Engine"),
|
||||
("car", "Car"),
|
||||
("railcar", "Railcar"),
|
||||
("equipment", "Equipment"),
|
||||
("other", "Other")
|
||||
]
|
||||
|
@@ -31,9 +31,10 @@ class ManufacturerAdmin(admin.ModelAdmin):
|
||||
@admin.register(Tag)
|
||||
class TagAdmin(admin.ModelAdmin):
|
||||
readonly_fields = ('slug',)
|
||||
list_display = ('name', 'slug')
|
||||
|
||||
|
||||
@admin.register(RollingStockType)
|
||||
class RollingStockTypeAdmin(admin.ModelAdmin):
|
||||
list_display = ('type', 'category')
|
||||
list_filter = list_display
|
||||
list_display = ('__str__',)
|
||||
list_filter = ('type', 'category')
|
||||
|
@@ -0,0 +1,26 @@
|
||||
# Generated by Django 4.0.2 on 2022-04-02 17:16
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('metadata', '0002_scale_manufacturer_website_and_more'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AlterModelOptions(
|
||||
name='company',
|
||||
options={'ordering': ['name'], 'verbose_name_plural': 'Companies'},
|
||||
),
|
||||
migrations.AlterModelOptions(
|
||||
name='scale',
|
||||
options={'ordering': ['scale']},
|
||||
),
|
||||
migrations.AlterField(
|
||||
model_name='rollingstocktype',
|
||||
name='category',
|
||||
field=models.CharField(choices=[('engine', 'Engine'), ('car', 'Car'), ('railcar', 'Railcar'), ('equipment', 'Equipment'), ('other', 'Other')], max_length=64),
|
||||
),
|
||||
]
|
@@ -0,0 +1,23 @@
|
||||
# Generated by Django 4.0.2 on 2022-04-02 17:45
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('metadata', '0003_alter_company_options_alter_scale_options_and_more'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AddField(
|
||||
model_name='company',
|
||||
name='freelance',
|
||||
field=models.BooleanField(blank=True, default=False, null=True),
|
||||
),
|
||||
migrations.AddField(
|
||||
model_name='decoder',
|
||||
name='sound',
|
||||
field=models.BooleanField(blank=True, default=False, null=True),
|
||||
),
|
||||
]
|
@@ -0,0 +1,23 @@
|
||||
# Generated by Django 4.0.2 on 2022-04-02 17:46
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('metadata', '0004_company_freelance_decoder_sound'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AlterField(
|
||||
model_name='company',
|
||||
name='freelance',
|
||||
field=models.BooleanField(default=False),
|
||||
),
|
||||
migrations.AlterField(
|
||||
model_name='decoder',
|
||||
name='sound',
|
||||
field=models.BooleanField(default=False),
|
||||
),
|
||||
]
|
@@ -26,6 +26,7 @@ class Company(models.Model):
|
||||
name = models.CharField(max_length=64, unique=True)
|
||||
extended_name = models.CharField(max_length=128, blank=True)
|
||||
country = CountryField()
|
||||
freelance = models.BooleanField(default=False)
|
||||
logo = models.ImageField(
|
||||
upload_to='images/',
|
||||
null=True,
|
||||
@@ -33,6 +34,7 @@ class Company(models.Model):
|
||||
|
||||
class Meta:
|
||||
verbose_name_plural = "Companies"
|
||||
ordering = ['name']
|
||||
|
||||
def __str__(self):
|
||||
return self.name
|
||||
@@ -53,6 +55,7 @@ class Decoder(models.Model):
|
||||
null=True,
|
||||
blank=True
|
||||
)
|
||||
sound = models.BooleanField(default=False)
|
||||
image = models.ImageField(
|
||||
upload_to='images/',
|
||||
null=True,
|
||||
@@ -71,6 +74,9 @@ class Scale(models.Model):
|
||||
ratio = models.CharField(max_length=16, blank=True)
|
||||
gauge = models.CharField(max_length=16, blank=True)
|
||||
|
||||
class Meta:
|
||||
ordering = ['scale']
|
||||
|
||||
def __str__(self):
|
||||
return str(self.scale)
|
||||
|
||||
@@ -97,4 +103,4 @@ class RollingStockType(models.Model):
|
||||
unique_together = ('category', 'type')
|
||||
|
||||
def __str__(self):
|
||||
return "{0}".format(self.type)
|
||||
return "{0} {1}".format(self.type, self.category)
|
||||
|
@@ -1,5 +1,13 @@
|
||||
from rest_framework import serializers
|
||||
from metadata.models import Manufacturer, Company, Decoder
|
||||
from metadata.models import (
|
||||
RollingStockType, Scale, Manufacturer,
|
||||
Company, Decoder, Tag)
|
||||
|
||||
|
||||
class RollingStockTypeSerializer(serializers.ModelSerializer):
|
||||
class Meta:
|
||||
model = RollingStockType
|
||||
fields = "__all__"
|
||||
|
||||
|
||||
class ManufacturerSerializer(serializers.ModelSerializer):
|
||||
@@ -8,6 +16,12 @@ class ManufacturerSerializer(serializers.ModelSerializer):
|
||||
fields = "__all__"
|
||||
|
||||
|
||||
class ScaleSerializer(serializers.ModelSerializer):
|
||||
class Meta:
|
||||
model = Scale
|
||||
fields = "__all__"
|
||||
|
||||
|
||||
class CompanySerializer(serializers.ModelSerializer):
|
||||
class Meta:
|
||||
model = Company
|
||||
@@ -20,3 +34,9 @@ class DecoderSerializer(serializers.ModelSerializer):
|
||||
class Meta:
|
||||
model = Decoder
|
||||
fields = "__all__"
|
||||
|
||||
|
||||
class TagSerializer(serializers.ModelSerializer):
|
||||
class Meta:
|
||||
model = Tag
|
||||
fields = "__all__"
|
||||
|
@@ -6,7 +6,7 @@ from roster.models import (
|
||||
@admin.register(RollingClass)
|
||||
class RollingClass(admin.ModelAdmin):
|
||||
list_display = ('__str__', 'type', 'company')
|
||||
list_filter = ('type', 'company')
|
||||
list_filter = ('company', 'type__category', 'type')
|
||||
search_fields = list_display
|
||||
|
||||
|
||||
@@ -28,8 +28,11 @@ class RollingStockAdmin(admin.ModelAdmin):
|
||||
inlines = (RollingStockImageInline, RollingStockDocInline)
|
||||
readonly_fields = ('creation_time', 'updated_time')
|
||||
list_display = (
|
||||
'__str__', 'manufacturer', 'scale', 'sku', 'company', 'country')
|
||||
list_filter = ('manufacturer', 'scale')
|
||||
'__str__', 'address', 'manufacturer',
|
||||
'scale', 'sku', 'company', 'country')
|
||||
list_filter = (
|
||||
'rolling_class__type__category', 'rolling_class__type',
|
||||
'scale', 'manufacturer')
|
||||
search_fields = list_display
|
||||
|
||||
fieldsets = (
|
||||
|
18
dcc/roster/migrations/0003_rollingstockimage_description.py
Normal file
18
dcc/roster/migrations/0003_rollingstockimage_description.py
Normal file
@@ -0,0 +1,18 @@
|
||||
# Generated by Django 4.0.2 on 2022-04-02 17:16
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('roster', '0002_rename_class_rollingclass_alter_rollingclass_options_and_more'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AddField(
|
||||
model_name='rollingstockimage',
|
||||
name='description',
|
||||
field=models.CharField(blank=True, max_length=256),
|
||||
),
|
||||
]
|
@@ -0,0 +1,22 @@
|
||||
# Generated by Django 4.0.2 on 2022-04-02 17:17
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('roster', '0003_rollingstockimage_description'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.RemoveField(
|
||||
model_name='rollingstockimage',
|
||||
name='description',
|
||||
),
|
||||
migrations.AddField(
|
||||
model_name='rollingclass',
|
||||
name='description',
|
||||
field=models.CharField(blank=True, max_length=256),
|
||||
),
|
||||
]
|
@@ -20,6 +20,7 @@ class RollingClass(models.Model):
|
||||
type = models.ForeignKey(
|
||||
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)
|
||||
|
@@ -1,13 +1,25 @@
|
||||
from rest_framework import serializers
|
||||
from roster.models import RollingStock
|
||||
from roster.models import RollingClass, RollingStock
|
||||
from metadata.serializers import (
|
||||
ManufacturerSerializer, CompanySerializer, DecoderSerializer)
|
||||
RollingStockTypeSerializer, ManufacturerSerializer, ScaleSerializer,
|
||||
CompanySerializer, DecoderSerializer, TagSerializer)
|
||||
|
||||
|
||||
class RollingClassSerializer(serializers.ModelSerializer):
|
||||
company = CompanySerializer()
|
||||
type = RollingStockTypeSerializer()
|
||||
|
||||
class Meta:
|
||||
model = RollingClass
|
||||
fields = "__all__"
|
||||
|
||||
|
||||
class RollingStockSerializer(serializers.ModelSerializer):
|
||||
rolling_class = RollingClassSerializer()
|
||||
manufacturer = ManufacturerSerializer()
|
||||
decoder = DecoderSerializer()
|
||||
company = CompanySerializer()
|
||||
scale = ScaleSerializer()
|
||||
tags = TagSerializer(many=True)
|
||||
|
||||
class Meta:
|
||||
model = RollingStock
|
||||
|
Reference in New Issue
Block a user