mirror of
https://github.com/daniviga/django-ram.git
synced 2025-08-04 13:17:50 +02:00
Add a journal for rolling stock
This commit is contained in:
@@ -47,6 +47,7 @@
|
||||
{% if rolling_stock.decoder %}<button class="nav-link" id="nav-dcc-tab" data-bs-toggle="tab" data-bs-target="#nav-dcc" type="button" role="tab" aria-controls="nav-dcc" aria-selected="false">DCC</button>{% endif %}
|
||||
{% if rolling_stock.notes %}<button class="nav-link" id="nav-notes-tab" data-bs-toggle="tab" data-bs-target="#nav-notes" type="button" role="tab" aria-controls="nav-notes" aria-selected="false">Notes</button>{% endif %}
|
||||
{% if rolling_stock.document.count > 0 %}<button class="nav-link" id="nav-documents-tab" data-bs-toggle="tab" data-bs-target="#nav-documents" type="button" role="tab" aria-controls="nav-documents" aria-selected="false">Documents</button>{% endif %}
|
||||
{% if rolling_stock_journal.count > 0 %}<button class="nav-link" id="nav-journal-tab" data-bs-toggle="tab" data-bs-target="#nav-journal" type="button" role="tab" aria-controls="nav-journal" aria-selected="false">Journal</button>{% endif %}
|
||||
</div>
|
||||
</nav>
|
||||
<div class="tab-content" id="nav-tabContent">
|
||||
@@ -277,6 +278,23 @@
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
<div class="tab-pane fade" id="nav-journal" role="tabpanel" aria-labelledby="nav-journal-tab">
|
||||
<table class="table table-striped">
|
||||
<thead>
|
||||
<tr>
|
||||
<th colspan="3" scope="row">Journal</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{% for j in rolling_stock_journal %}
|
||||
<tr>
|
||||
<th width="35%" scope="row">{{ j.date }}</th>
|
||||
<td>{{ j.log | safe }}</a></td>
|
||||
</tr>
|
||||
{% endfor %}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
<div class="d-grid gap-2 d-md-flex justify-content-md-end">
|
||||
{% if request.user.is_staff %}<a class="btn btn-sm btn-outline-danger" href="{% url 'admin:roster_rollingstock_change' rolling_stock.pk %}">Edit</a>{% endif %}
|
||||
|
@@ -154,6 +154,12 @@ class GetRollingStock(View):
|
||||
else rolling_stock.property.filter(property__private=False)
|
||||
)
|
||||
|
||||
rolling_stock_journal = (
|
||||
rolling_stock.journal.all()
|
||||
if request.user.is_authenticated
|
||||
else rolling_stock.journal.filter(private=False)
|
||||
)
|
||||
|
||||
return render(
|
||||
request,
|
||||
"page.html",
|
||||
@@ -161,6 +167,7 @@ class GetRollingStock(View):
|
||||
"rolling_stock": rolling_stock,
|
||||
"class_properties": class_properties,
|
||||
"rolling_stock_properties": rolling_stock_properties,
|
||||
"rolling_stock_journal": rolling_stock_journal,
|
||||
},
|
||||
)
|
||||
|
||||
|
@@ -6,6 +6,7 @@ from roster.models import (
|
||||
RollingStockImage,
|
||||
RollingStockDocument,
|
||||
RollingStockProperty,
|
||||
RollingStockJournal,
|
||||
)
|
||||
|
||||
|
||||
@@ -31,6 +32,7 @@ class RollingStockDocInline(admin.TabularInline):
|
||||
model = RollingStockDocument
|
||||
min_num = 0
|
||||
extra = 0
|
||||
classes = ["collapse"]
|
||||
|
||||
|
||||
class RollingStockImageInline(admin.TabularInline):
|
||||
@@ -38,6 +40,7 @@ class RollingStockImageInline(admin.TabularInline):
|
||||
min_num = 0
|
||||
extra = 0
|
||||
readonly_fields = ("image_thumbnail",)
|
||||
classes = ["collapse"]
|
||||
|
||||
|
||||
class RollingStockPropertyInline(admin.TabularInline):
|
||||
@@ -46,6 +49,13 @@ class RollingStockPropertyInline(admin.TabularInline):
|
||||
extra = 0
|
||||
|
||||
|
||||
class RollingStockJournalInline(admin.TabularInline):
|
||||
model = RollingStockJournal
|
||||
min_num = 0
|
||||
extra = 0
|
||||
classes = ["collapse"]
|
||||
|
||||
|
||||
@admin.register(RollingStockDocument)
|
||||
class RollingStockDocumentAdmin(admin.ModelAdmin):
|
||||
list_display = (
|
||||
@@ -62,12 +72,33 @@ class RollingStockDocumentAdmin(admin.ModelAdmin):
|
||||
)
|
||||
|
||||
|
||||
@admin.register(RollingStockJournal)
|
||||
class RollingJournalDocumentAdmin(admin.ModelAdmin):
|
||||
list_display = (
|
||||
"__str__",
|
||||
"date",
|
||||
"rolling_stock",
|
||||
"private",
|
||||
)
|
||||
list_filter = (
|
||||
"date",
|
||||
"private",
|
||||
)
|
||||
search_fields = (
|
||||
"rolling_stock__rolling_class__identifier",
|
||||
"rolling_stock__road_number",
|
||||
"rolling_stock__sku",
|
||||
"log",
|
||||
)
|
||||
|
||||
|
||||
@admin.register(RollingStock)
|
||||
class RollingStockAdmin(admin.ModelAdmin):
|
||||
inlines = (
|
||||
RollingStockPropertyInline,
|
||||
RollingStockImageInline,
|
||||
RollingStockDocInline,
|
||||
RollingStockJournalInline,
|
||||
)
|
||||
readonly_fields = ("creation_time", "updated_time")
|
||||
list_display = (
|
||||
|
45
ram/roster/migrations/0012_rollingstockjournal.py
Normal file
45
ram/roster/migrations/0012_rollingstockjournal.py
Normal file
@@ -0,0 +1,45 @@
|
||||
# Generated by Django 4.1 on 2022-08-27 12:43
|
||||
|
||||
import ckeditor_uploader.fields
|
||||
from django.db import migrations, models
|
||||
import django.db.models.deletion
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
("roster", "0011_md_to_html"),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.CreateModel(
|
||||
name="RollingStockJournal",
|
||||
fields=[
|
||||
(
|
||||
"id",
|
||||
models.BigAutoField(
|
||||
auto_created=True,
|
||||
primary_key=True,
|
||||
serialize=False,
|
||||
verbose_name="ID",
|
||||
),
|
||||
),
|
||||
("date", models.DateField()),
|
||||
("log", ckeditor_uploader.fields.RichTextUploadingField()),
|
||||
("private", models.BooleanField(default=False)),
|
||||
("creation_time", models.DateTimeField(auto_now_add=True)),
|
||||
("updated_time", models.DateTimeField(auto_now=True)),
|
||||
(
|
||||
"rolling_stock",
|
||||
models.ForeignKey(
|
||||
on_delete=django.db.models.deletion.CASCADE,
|
||||
related_name="journal",
|
||||
to="roster.rollingstock",
|
||||
),
|
||||
),
|
||||
],
|
||||
options={
|
||||
"ordering": ["date", "rolling_stock"],
|
||||
},
|
||||
),
|
||||
]
|
@@ -191,6 +191,27 @@ class RollingStockProperty(models.Model):
|
||||
verbose_name_plural = "Properties"
|
||||
|
||||
|
||||
class RollingStockJournal(models.Model):
|
||||
rolling_stock = models.ForeignKey(
|
||||
RollingStock,
|
||||
on_delete=models.CASCADE,
|
||||
related_name="journal",
|
||||
null=False,
|
||||
blank=False,
|
||||
)
|
||||
date = models.DateField()
|
||||
log = RichTextUploadingField()
|
||||
private = models.BooleanField(default=False)
|
||||
creation_time = models.DateTimeField(auto_now_add=True)
|
||||
updated_time = models.DateTimeField(auto_now=True)
|
||||
|
||||
def __str__(self):
|
||||
return "{0} - {1}".format(self.rolling_stock, self.date)
|
||||
|
||||
class Meta:
|
||||
ordering = ["date", "rolling_stock"]
|
||||
|
||||
|
||||
# @receiver(models.signals.post_delete, sender=Cab)
|
||||
# def post_save_image(sender, instance, *args, **kwargs):
|
||||
# try:
|
||||
|
Reference in New Issue
Block a user