paperwork: Use default names for certification-related models

This commit is contained in:
Adam Goldsmith 2023-04-10 14:51:43 -04:00
parent bb6577f3bb
commit 35f812d2c6
9 changed files with 116 additions and 36 deletions

View File

@ -80,9 +80,9 @@ class CertificationVersionInline(admin.TabularInline):
@admin.register(CertificationDefinition)
class CertificationDefinitionAdmin(admin.ModelAdmin):
search_fields = ["certification_name"]
search_fields = ["name"]
list_display = [
"certification_name",
"name",
"department",
"latest_semantic_version",
]
@ -103,7 +103,7 @@ class CertificationAdmin(admin.ModelAdmin):
form = CertificationForm
search_fields = [
"name",
"certification_version__definition__certification_name",
"certification_version__definition__name",
"certification_version__definition__department__name",
]
autocomplete_fields = ["member"]
@ -116,10 +116,10 @@ class CertificationAdmin(admin.ModelAdmin):
@admin.display(
description="Certification Name",
ordering="certification_version__definition__certification_name",
ordering="certification_version__definition__name",
)
def certification_name(self, obj: Certification) -> str:
return obj.certification_version.definition.certification_name
def name(self, obj: Certification) -> str:
return obj.certification_version.definition.name
@admin.display(
description="Certification Version",
@ -152,7 +152,7 @@ class CertificationAdmin(admin.ModelAdmin):
return obj.audits.latest()
list_display = [
"certification_name",
"name",
"name",
"certification_semantic_version",
"is_current",
@ -163,7 +163,7 @@ class CertificationAdmin(admin.ModelAdmin):
"latest_audit",
]
list_display_links = [
"certification_name",
"name",
"name",
]
list_filter = [

View File

@ -104,7 +104,7 @@ class DepartmentViewSet(viewsets.ModelViewSet):
class CertificationDefinitionSerializer(serializers.HyperlinkedModelSerializer):
class Meta:
model = CertificationDefinition
fields = ["certification_name", "department"]
fields = ["name", "department"]
class CertificationDefinitionViewSet(viewsets.ModelViewSet):

View File

@ -0,0 +1,92 @@
# Generated by Django 4.2 on 2023-04-10 18:37
from django.db import migrations, models
import django.db.models.deletion
class Migration(migrations.Migration):
dependencies = [
("membershipworks", "0002_alter_flag_options"),
("paperwork", "0013_alter_certificationdefinition_certification_name"),
]
operations = [
migrations.RenameField(
model_name="certificationdefinition",
old_name="certification_identifier",
new_name="id",
),
migrations.AlterField(
model_name="certificationdefinition",
name="id",
field=models.BigAutoField(
auto_created=True,
primary_key=True,
serialize=False,
verbose_name="ID",
),
),
migrations.AlterField(
model_name="certification",
name="certified_by",
field=models.CharField(blank=True, max_length=255, null=True),
),
migrations.AlterField(
model_name="certification",
name="date",
field=models.DateField(blank=True, null=True),
),
migrations.AlterField(
model_name="certification",
name="member",
field=models.ForeignKey(
blank=True,
db_constraint=False,
null=True,
on_delete=django.db.models.deletion.PROTECT,
to="membershipworks.member",
),
),
migrations.AlterField(
model_name="certification",
name="name",
field=models.CharField(max_length=255),
),
migrations.AlterField(
model_name="certification",
name="notes",
field=models.CharField(blank=True, max_length=255, null=True),
),
migrations.AlterField(
model_name="certification",
name="number",
field=models.AutoField(primary_key=True, serialize=False),
),
migrations.AlterField(
model_name="certification",
name="shop_lead_notified",
field=models.DateTimeField(blank=True, null=True),
),
migrations.AlterField(
model_name="certificationdefinition",
name="certification_name",
field=models.CharField(max_length=255),
),
migrations.RenameField(
model_name="certificationdefinition",
old_name="certification_name",
new_name="name",
),
migrations.AlterModelOptions(
name="certificationdefinition",
options={"ordering": ("name", "department")},
),
migrations.AlterField(
model_name="certificationversion",
name="definition",
field=models.ForeignKey(
on_delete=django.db.models.deletion.PROTECT,
to="paperwork.certificationdefinition",
),
),
]

View File

@ -105,20 +105,15 @@ class Department(models.Model):
class CertificationDefinition(models.Model):
certification_identifier = models.AutoField(
db_column="Certification Identifier", primary_key=True
)
certification_name = models.CharField(
db_column="Certification Name", max_length=255
)
name = models.CharField(max_length=255)
department = models.ForeignKey(Department, models.PROTECT)
def __str__(self) -> str:
return f"{self.certification_name} <{self.department}>"
return f"{self.name} <{self.department}>"
class Meta:
db_table = "Certification Definitions"
ordering = ("certification_name", "department")
ordering = ("name", "department")
def latest_version(self) -> "CertificationVersion":
return self.certificationversion_set.latest()
@ -149,9 +144,7 @@ class CertificationVersionManager(models.Manager["CertificationVersion"]):
class CertificationVersion(models.Model):
objects = CertificationVersionManager()
definition = models.ForeignKey(
CertificationDefinition, on_delete=models.PROTECT, db_column="Certification"
)
definition = models.ForeignKey(CertificationDefinition, on_delete=models.PROTECT)
major = models.PositiveSmallIntegerField()
minor = models.PositiveSmallIntegerField()
patch = models.PositiveSmallIntegerField()
@ -198,28 +191,23 @@ else:
class Certification(models.Model):
number = models.AutoField(db_column="Number", primary_key=True)
number = models.AutoField(primary_key=True)
certification_version = models.ForeignKey(
CertificationVersion, on_delete=models.PROTECT
)
name = models.CharField(db_column="Name", max_length=255)
name = models.CharField(max_length=255)
member = models.ForeignKey(
Member,
on_delete=models.PROTECT,
to_field="uid",
db_column="uid",
blank=True,
null=True,
db_constraint=False,
)
certified_by = models.CharField(
db_column="Certified_By", max_length=255, blank=True, null=True
)
date = models.DateField(db_column="Date", blank=True, null=True)
shop_lead_notified = models.DateTimeField(
db_column="Shop Lead Notified", blank=True, null=True
)
notes = models.CharField(db_column="Notes", max_length=255, blank=True, null=True)
certified_by = models.CharField(max_length=255, blank=True, null=True)
date = models.DateField(blank=True, null=True)
shop_lead_notified = models.DateTimeField(blank=True, null=True)
notes = models.CharField(max_length=255, blank=True, null=True)
def __str__(self) -> str:
return f"{self.name} - {self.certification_version}"

View File

@ -48,7 +48,7 @@
{% for certification in certifications %}
<tr>
<td>{{ certification.certification_version.definition.department.name }}</td>
<td>{{ certification.certification_version.definition.certification_name }}</td>
<td>{{ certification.certification_version.definition.name }}</td>
<td>{{ certification.member|default:certification.name }}</td>
<td>
{% if not certification.certification_version.is_current %}[OUTDATED]{% endif %}

View File

@ -10,7 +10,7 @@
</tr>
{% for certification in certifications %}
<tr>
<td>{{ certification.certification_version.definition.certification_name }}</td>
<td>{{ certification.certification_version.definition.name }}</td>
<td>{{ certification.certification_version.semantic_version }}</td>
<td>{{ certification.member }}</td>
<td>{{ certification.certification_version.definition.department }}</td>

View File

@ -14,7 +14,7 @@
</tr>
{% for certification in certifications %}
<tr>
<td>{{ certification.certification_version.definition.certification_name }}</td>
<td>{{ certification.certification_version.definition.name }}</td>
<td>{{ certification.certification_version.semantic_version }}</td>
<td>{{ certification.member }}</td>
<td>{{ certification.certified_by }}</td>

View File

@ -12,7 +12,7 @@
</tr>
{% for certification in certifications %}
<tr>
<td>{{ certification.certification_version.definition.certification_name }}</td>
<td>{{ certification.certification_version.definition.name }}</td>
<td>{{ certification.certification_version.semantic_version }}</td>
<td>{{ certification.certification_version.definition.department }}</td>
<td>{{ certification.certified_by }}</td>

View File

@ -27,7 +27,7 @@
{% if current or show_outdated %}
<tr {% if not current %} class="table-warning"{% endif %}>
<td {% if not current %} class="text-decoration-line-through"{% endif %}>
{{ certification.certification_version.definition.certification_name }}
{{ certification.certification_version.definition.name }}
</td>
<td>
{{ certification.certification_version.semantic_version }}