diff --git a/ram/bookshelf/admin.py b/ram/bookshelf/admin.py
index 1c18986..2cb980d 100644
--- a/ram/bookshelf/admin.py
+++ b/ram/bookshelf/admin.py
@@ -11,7 +11,7 @@ from portal.utils import get_site_conf
from repository.models import (
BookDocument,
CatalogDocument,
- MagazineIssueDocument
+ MagazineIssueDocument,
)
from bookshelf.models import (
BaseBookProperty,
@@ -66,12 +66,12 @@ class BookAdmin(SortableAdminBase, admin.ModelAdmin):
BookDocInline,
)
list_display = (
+ "published",
"title",
"get_authors",
"get_publisher",
"publication_year",
"number_of_pages",
- "published",
)
autocomplete_fields = ("authors", "publisher", "shop")
readonly_fields = ("invoices", "creation_time", "updated_time")
@@ -135,8 +135,8 @@ class BookAdmin(SortableAdminBase, admin.ModelAdmin):
if obj.invoice.exists():
html = format_html_join(
"
",
- "{}",
- ((i.file.url, i) for i in obj.invoice.all())
+ '{}',
+ ((i.file.url, i) for i in obj.invoice.all()),
)
else:
html = "-"
@@ -212,11 +212,11 @@ class AuthorAdmin(admin.ModelAdmin):
@admin.register(Publisher)
class PublisherAdmin(admin.ModelAdmin):
- list_display = ("name", "country_flag")
+ list_display = ("name", "country_flag_name")
search_fields = ("name",)
@admin.display(description="Country")
- def country_flag(self, obj):
+ def country_flag_name(self, obj):
return format_html(
' {}', obj.country.flag, obj.country.name
)
@@ -240,10 +240,10 @@ class CatalogAdmin(SortableAdminBase, admin.ModelAdmin):
readonly_fields = ("invoices", "creation_time", "updated_time")
search_fields = ("manufacturer__name", "years", "scales__scale")
list_filter = (
+ "published",
"manufacturer__name",
"publication_year",
"scales__scale",
- "published",
)
fieldsets = (
@@ -303,8 +303,8 @@ class CatalogAdmin(SortableAdminBase, admin.ModelAdmin):
if obj.invoice.exists():
html = format_html_join(
"
",
- "{}",
- ((i.file.url, i) for i in obj.invoice.all())
+ '{}',
+ ((i.file.url, i) for i in obj.invoice.all()),
)
else:
html = "-"
@@ -449,14 +449,12 @@ class MagazineIssueInline(admin.TabularInline):
readonly_fields = ("preview",)
class Media:
- js = ('admin/js/magazine_issue_defaults.js',)
+ js = ("admin/js/magazine_issue_defaults.js",)
@admin.register(Magazine)
class MagazineAdmin(SortableAdminBase, admin.ModelAdmin):
- inlines = (
- MagazineIssueInline,
- )
+ inlines = (MagazineIssueInline,)
list_display = (
"__str__",
@@ -466,7 +464,10 @@ class MagazineAdmin(SortableAdminBase, admin.ModelAdmin):
autocomplete_fields = ("publisher",)
readonly_fields = ("creation_time", "updated_time")
search_fields = ("name", "publisher__name")
- list_filter = ("publisher__name", "published")
+ list_filter = (
+ "published",
+ "publisher__name",
+ )
fieldsets = (
(
diff --git a/ram/bookshelf/models.py b/ram/bookshelf/models.py
index 0fb498f..46062c7 100644
--- a/ram/bookshelf/models.py
+++ b/ram/bookshelf/models.py
@@ -224,6 +224,10 @@ class MagazineIssue(BaseBook):
"published."
)
+ @property
+ def obj_label(self):
+ return "Magazine Issue"
+
def preview(self):
return self.image.first().image_thumbnail(100)
diff --git a/ram/consist/admin.py b/ram/consist/admin.py
index 135760a..1344952 100644
--- a/ram/consist/admin.py
+++ b/ram/consist/admin.py
@@ -2,6 +2,7 @@ import html
from django.conf import settings
from django.contrib import admin
+
# from django.forms import BaseInlineFormSet # for future reference
from django.utils.html import format_html, strip_tags
from adminsortable2.admin import (
@@ -46,15 +47,22 @@ class ConsistAdmin(SortableAdminBase, admin.ModelAdmin):
"creation_time",
"updated_time",
)
- list_filter = ("company__name", "era", "scale", "published")
- list_display = ("__str__",) + list_filter + ("country_flag",)
+ list_filter = ("published", "company__name", "era", "scale")
+ list_display = (
+ "__str__",
+ "company__name",
+ "era",
+ "scale",
+ "country_flag",
+ "published",
+ )
search_fields = ("identifier",) + list_filter
save_as = True
@admin.display(description="Country")
def country_flag(self, obj):
return format_html(
- ' {}', obj.country.flag, obj.country
+ '
', obj.country.flag, obj.country.name
)
fieldsets = (
@@ -138,6 +146,7 @@ class ConsistAdmin(SortableAdminBase, admin.ModelAdmin):
)
return generate_csv(header, data, "consists.csv")
+
download_csv.short_description = "Download selected items as CSV"
actions = [publish, unpublish, download_csv]
diff --git a/ram/metadata/admin.py b/ram/metadata/admin.py
index d3f30b5..ec91a0a 100644
--- a/ram/metadata/admin.py
+++ b/ram/metadata/admin.py
@@ -47,12 +47,12 @@ class ScaleAdmin(admin.ModelAdmin):
@admin.register(Company)
class CompanyAdmin(admin.ModelAdmin):
readonly_fields = ("logo_thumbnail",)
- list_display = ("name", "country_flag")
+ list_display = ("name", "country_flag_name")
list_filter = ("name", "country")
search_fields = ("name",)
@admin.display(description="Country")
- def country_flag(self, obj):
+ def country_flag_name(self, obj):
return format_html(
'
{}', obj.country.flag, obj.country.name
)
@@ -61,12 +61,12 @@ class CompanyAdmin(admin.ModelAdmin):
@admin.register(Manufacturer)
class ManufacturerAdmin(admin.ModelAdmin):
readonly_fields = ("logo_thumbnail",)
- list_display = ("name", "category", "country_flag")
+ list_display = ("name", "category", "country_flag_name")
list_filter = ("category",)
search_fields = ("name",)
@admin.display(description="Country")
- def country_flag(self, obj):
+ def country_flag_name(self, obj):
return format_html(
'
{}', obj.country.flag, obj.country.name
)
@@ -88,6 +88,12 @@ class RollingStockTypeAdmin(SortableAdminMixin, admin.ModelAdmin):
@admin.register(Shop)
class ShopAdmin(admin.ModelAdmin):
- list_display = ("name", "on_line", "active")
+ list_display = ("name", "on_line", "active", "country_flag_name")
list_filter = ("on_line", "active")
search_fields = ("name",)
+
+ @admin.display(description="Country")
+ def country_flag_name(self, obj):
+ return format_html(
+ '
{}', obj.country.flag, obj.country.name
+ )
diff --git a/ram/metadata/models.py b/ram/metadata/models.py
index a956738..4ef63b5 100644
--- a/ram/metadata/models.py
+++ b/ram/metadata/models.py
@@ -7,11 +7,12 @@ from django.dispatch.dispatcher import receiver
from django.core.exceptions import ValidationError
from django_countries.fields import CountryField
+from ram.models import SimpleBaseModel
from ram.utils import DeduplicatedStorage, get_image_preview, slugify
from ram.managers import PublicManager
-class Property(models.Model):
+class Property(SimpleBaseModel):
name = models.CharField(max_length=128, unique=True)
private = models.BooleanField(
default=False,
@@ -28,7 +29,7 @@ class Property(models.Model):
objects = PublicManager()
-class Manufacturer(models.Model):
+class Manufacturer(SimpleBaseModel):
name = models.CharField(max_length=128, unique=True)
slug = models.CharField(max_length=128, unique=True, editable=False)
category = models.CharField(
@@ -68,7 +69,7 @@ class Manufacturer(models.Model):
logo_thumbnail.short_description = "Preview"
-class Company(models.Model):
+class Company(SimpleBaseModel):
name = models.CharField(max_length=64, unique=True)
slug = models.CharField(max_length=64, unique=True, editable=False)
extended_name = models.CharField(max_length=128, blank=True)
@@ -106,7 +107,7 @@ class Company(models.Model):
logo_thumbnail.short_description = "Preview"
-class Decoder(models.Model):
+class Decoder(SimpleBaseModel):
name = models.CharField(max_length=128, unique=True)
manufacturer = models.ForeignKey(
Manufacturer,
@@ -142,7 +143,7 @@ def calculate_ratio(ratio):
raise ValidationError("Invalid ratio format")
-class Scale(models.Model):
+class Scale(SimpleBaseModel):
scale = models.CharField(max_length=32, unique=True)
slug = models.CharField(max_length=32, unique=True, editable=False)
ratio = models.CharField(max_length=16, validators=[calculate_ratio])
@@ -177,7 +178,7 @@ def scale_save(sender, instance, **kwargs):
instance.ratio_int = calculate_ratio(instance.ratio)
-class RollingStockType(models.Model):
+class RollingStockType(SimpleBaseModel):
type = models.CharField(max_length=64)
order = models.PositiveSmallIntegerField()
category = models.CharField(
@@ -207,7 +208,7 @@ class RollingStockType(models.Model):
return "{0} {1}".format(self.type, self.category)
-class Tag(models.Model):
+class Tag(SimpleBaseModel):
name = models.CharField(max_length=128, unique=True)
slug = models.CharField(max_length=128, unique=True)
@@ -227,7 +228,7 @@ class Tag(models.Model):
)
-class Shop(models.Model):
+class Shop(SimpleBaseModel):
name = models.CharField(max_length=128, unique=True)
country = CountryField(blank=True)
website = models.URLField(blank=True)
diff --git a/ram/portal/templates/bookshelf/book.html b/ram/portal/templates/bookshelf/book.html
index 2a3159d..ea1eb3a 100644
--- a/ram/portal/templates/bookshelf/book.html
+++ b/ram/portal/templates/bookshelf/book.html
@@ -2,23 +2,23 @@
{% load dynamic_url %}
{% block header %}
- {% if book.tags.all %}
+ {% if data.tags.all %}
Tags: - {% for t in book.tags.all %} + {% for t in data.tags.all %} {{ t.name }}{# new line is required #} {% endfor %}
{% endif %} - {% if not book.published %} + {% if not data.published %} Unpublished | {% endif %} - Updated {{ book.updated_time | date:"M d, Y H:i" }} + Updated {{ data.updated_time | date:"M d, Y H:i" }} {% endblock %} {% block carousel %}Tags:
- {% for t in d.item.tags.all %}
+ {% for t in d.tags.all %}
{{ t.name }}{# new line is required #}
{% empty %}
@@ -24,9 +24,9 @@
- {{ d.label|capfirst }}
+ {{ d.obj_label|capfirst }}
- {{ d.item.name }} + {{ d.name }}
|
Company
- {% if d.item.freelance %}
+ {% if d.freelance %}
Freelance
{% endif %}
@@ -18,30 +18,30 @@
|
- {% if d.item.logo %}
+ {% if d.logo %}
||
|---|---|---|
| Logo | -||
| Name | -{{ d.item.extended_name }} | +{{ d.extended_name }} |
| Abbreviation | -{{ d.item.name }} | +{{ d.name }} |
| Country | -
Tags: - {% for t in d.item.tags.all %} + {% for t in d.tags.all %} {{ t.name }}{# new line is required #} {% empty %} @@ -27,10 +27,10 @@
Tags:
- {% for t in d.item.tags.all %}
+ {% for t in d.tags.all %}
{{ t.name }}{# new line is required #}
{% empty %}
@@ -42,10 +42,10 @@
- {{ d.label|capfirst }}
+ {{ d.obj_label|capfirst }}
- {{ d.item.name }} + {{ d.name }}
| Logo | -||
|---|---|---|
| Website | -{% if d.item.website %}{{ d.item.website_short }} | {% else %}-{% endif %} +{% if d.website %}{{ d.website_short }} | {% else %}-{% endif %}
| Category | -{{ d.item.category | title }} | +{{ d.category | title }} |
{{ d.item }}
+{{ d }}
| Type | -{{ d.item.type }} | +{{ d.type }} |
|---|---|---|
| Category | -{{ d.item.category | title}} | +{{ d.category | title}} |
Tags: - {% for t in d.item.tags.all %} + {% for t in d.tags.all %} {{ t.name }}{# new line is required #} {% empty %} @@ -27,10 +27,10 @@
{{ d.item }}
+{{ d }}
| Name | -{{ d.item.scale }} | +{{ d.scale }} |
|---|---|---|
| Ratio | -{{ d.item.ratio }} | +{{ d.ratio }} |
| Tracks | -{{ d.item.tracks }} mm | +{{ d.tracks }} mm |
| Gauge | -{{ d.item.gauge }} | +{{ d.gauge }} |