mirror of
https://github.com/daniviga/django-ram.git
synced 2025-08-04 13:17:50 +02:00
Improve user experience in admin and UI (#45)
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
from django.contrib import admin
|
||||
from django.utils.html import format_html
|
||||
from adminsortable2.admin import SortableAdminMixin
|
||||
|
||||
from ram.admin import publish, unpublish
|
||||
@@ -47,18 +48,30 @@ class ScaleAdmin(admin.ModelAdmin):
|
||||
@admin.register(Company)
|
||||
class CompanyAdmin(admin.ModelAdmin):
|
||||
readonly_fields = ("logo_thumbnail",)
|
||||
list_display = ("name", "country")
|
||||
list_filter = list_display
|
||||
list_display = ("name", "country_flag")
|
||||
list_filter = ("name", "country")
|
||||
search_fields = ("name",)
|
||||
|
||||
@admin.display(description="Country")
|
||||
def country_flag(self, obj):
|
||||
return format_html(
|
||||
'<img src="{}" /> {}'.format(obj.country.flag, obj.country.name)
|
||||
)
|
||||
|
||||
|
||||
@admin.register(Manufacturer)
|
||||
class ManufacturerAdmin(admin.ModelAdmin):
|
||||
readonly_fields = ("logo_thumbnail",)
|
||||
list_display = ("name", "category")
|
||||
list_display = ("name", "category", "country_flag")
|
||||
list_filter = ("category",)
|
||||
search_fields = ("name",)
|
||||
|
||||
@admin.display(description="Country")
|
||||
def country_flag(self, obj):
|
||||
return format_html(
|
||||
'<img src="{}" /> {}'.format(obj.country.flag, obj.country.name)
|
||||
)
|
||||
|
||||
|
||||
@admin.register(Tag)
|
||||
class TagAdmin(admin.ModelAdmin):
|
||||
@@ -76,7 +89,7 @@ class RollingStockTypeAdmin(SortableAdminMixin, admin.ModelAdmin):
|
||||
|
||||
@admin.register(GenericDocument)
|
||||
class GenericDocumentAdmin(admin.ModelAdmin):
|
||||
readonly_fields = ("size",)
|
||||
readonly_fields = ("size", "creation_time", "updated_time")
|
||||
list_display = (
|
||||
"__str__",
|
||||
"description",
|
||||
@@ -88,4 +101,32 @@ class GenericDocumentAdmin(admin.ModelAdmin):
|
||||
"description",
|
||||
"file",
|
||||
)
|
||||
fieldsets = (
|
||||
(
|
||||
None,
|
||||
{
|
||||
"fields": (
|
||||
"private",
|
||||
"description",
|
||||
"file",
|
||||
"size",
|
||||
"tags",
|
||||
)
|
||||
},
|
||||
),
|
||||
(
|
||||
"Notes",
|
||||
{"classes": ("collapse",), "fields": ("notes",)},
|
||||
),
|
||||
(
|
||||
"Audit",
|
||||
{
|
||||
"classes": ("collapse",),
|
||||
"fields": (
|
||||
"creation_time",
|
||||
"updated_time",
|
||||
),
|
||||
},
|
||||
),
|
||||
)
|
||||
actions = [publish, unpublish]
|
||||
|
@@ -0,0 +1,66 @@
|
||||
# Generated by Django 5.1.4 on 2025-01-18 11:20
|
||||
|
||||
import django.utils.timezone
|
||||
import django_countries.fields
|
||||
import tinymce.models
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
("metadata", "0021_genericdocument"),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AddField(
|
||||
model_name="decoderdocument",
|
||||
name="creation_time",
|
||||
field=models.DateTimeField(
|
||||
auto_now_add=True, default=django.utils.timezone.now
|
||||
),
|
||||
preserve_default=False,
|
||||
),
|
||||
migrations.AddField(
|
||||
model_name="decoderdocument",
|
||||
name="updated_time",
|
||||
field=models.DateTimeField(auto_now=True),
|
||||
),
|
||||
migrations.AddField(
|
||||
model_name="genericdocument",
|
||||
name="creation_time",
|
||||
field=models.DateTimeField(
|
||||
auto_now_add=True, default=django.utils.timezone.now
|
||||
),
|
||||
preserve_default=False,
|
||||
),
|
||||
migrations.AddField(
|
||||
model_name="genericdocument",
|
||||
name="notes",
|
||||
field=tinymce.models.HTMLField(blank=True),
|
||||
),
|
||||
migrations.AddField(
|
||||
model_name="genericdocument",
|
||||
name="updated_time",
|
||||
field=models.DateTimeField(auto_now=True),
|
||||
),
|
||||
migrations.AddField(
|
||||
model_name="manufacturer",
|
||||
name="country",
|
||||
field=django_countries.fields.CountryField(blank=True, max_length=2),
|
||||
),
|
||||
migrations.AlterField(
|
||||
model_name="decoderdocument",
|
||||
name="private",
|
||||
field=models.BooleanField(
|
||||
default=False, help_text="Document will be visible only to logged users"
|
||||
),
|
||||
),
|
||||
migrations.AlterField(
|
||||
model_name="genericdocument",
|
||||
name="private",
|
||||
field=models.BooleanField(
|
||||
default=False, help_text="Document will be visible only to logged users"
|
||||
),
|
||||
),
|
||||
]
|
@@ -6,6 +6,8 @@ from django.dispatch.dispatcher import receiver
|
||||
from django.core.exceptions import ValidationError
|
||||
from django_countries.fields import CountryField
|
||||
|
||||
from tinymce import models as tinymce
|
||||
|
||||
from ram.models import Document
|
||||
from ram.utils import DeduplicatedStorage, get_image_preview, slugify
|
||||
from ram.managers import PublicManager
|
||||
@@ -34,6 +36,7 @@ class Manufacturer(models.Model):
|
||||
category = models.CharField(
|
||||
max_length=64, choices=settings.MANUFACTURER_TYPES
|
||||
)
|
||||
country = CountryField(blank=True)
|
||||
website = models.URLField(blank=True)
|
||||
logo = models.ImageField(
|
||||
upload_to=os.path.join("images", "manufacturers"),
|
||||
@@ -237,6 +240,7 @@ class Tag(models.Model):
|
||||
|
||||
|
||||
class GenericDocument(Document):
|
||||
notes = tinymce.HTMLField(blank=True)
|
||||
tags = models.ManyToManyField(Tag, blank=True)
|
||||
|
||||
class Meta:
|
||||
|
Reference in New Issue
Block a user