diff --git a/paperwork/admin.py b/paperwork/admin.py index 83b6ce9..0dec7fb 100644 --- a/paperwork/admin.py +++ b/paperwork/admin.py @@ -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 = [ diff --git a/paperwork/api.py b/paperwork/api.py index ce84772..1e066a4 100644 --- a/paperwork/api.py +++ b/paperwork/api.py @@ -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): diff --git a/paperwork/migrations/0014_alter_certificationdefinition_options_and_more.py b/paperwork/migrations/0014_alter_certificationdefinition_options_and_more.py new file mode 100644 index 0000000..275e5bd --- /dev/null +++ b/paperwork/migrations/0014_alter_certificationdefinition_options_and_more.py @@ -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", + ), + ), + ] diff --git a/paperwork/models.py b/paperwork/models.py index 951be4a..12ff107 100644 --- a/paperwork/models.py +++ b/paperwork/models.py @@ -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}" diff --git a/paperwork/templates/paperwork/department_certifications.dj.html b/paperwork/templates/paperwork/department_certifications.dj.html index 492ffa5..7d1c835 100644 --- a/paperwork/templates/paperwork/department_certifications.dj.html +++ b/paperwork/templates/paperwork/department_certifications.dj.html @@ -48,7 +48,7 @@ {% for certification in certifications %} {{ certification.certification_version.definition.department.name }} - {{ certification.certification_version.definition.certification_name }} + {{ certification.certification_version.definition.name }} {{ certification.member|default:certification.name }} {% if not certification.certification_version.is_current %}[OUTDATED]{% endif %} diff --git a/paperwork/templates/paperwork/email/admin_certifications.dj.html b/paperwork/templates/paperwork/email/admin_certifications.dj.html index 16ba298..6bb726a 100644 --- a/paperwork/templates/paperwork/email/admin_certifications.dj.html +++ b/paperwork/templates/paperwork/email/admin_certifications.dj.html @@ -10,7 +10,7 @@ {% for certification in certifications %} - {{ certification.certification_version.definition.certification_name }} + {{ certification.certification_version.definition.name }} {{ certification.certification_version.semantic_version }} {{ certification.member }} {{ certification.certification_version.definition.department }} diff --git a/paperwork/templates/paperwork/email/department_certifications.dj.html b/paperwork/templates/paperwork/email/department_certifications.dj.html index 4c55874..5d1c53b 100644 --- a/paperwork/templates/paperwork/email/department_certifications.dj.html +++ b/paperwork/templates/paperwork/email/department_certifications.dj.html @@ -14,7 +14,7 @@ {% for certification in certifications %} - {{ certification.certification_version.definition.certification_name }} + {{ certification.certification_version.definition.name }} {{ certification.certification_version.semantic_version }} {{ certification.member }} {{ certification.certified_by }} diff --git a/paperwork/templates/paperwork/email/member_certifications.dj.html b/paperwork/templates/paperwork/email/member_certifications.dj.html index e0d4a86..a928704 100644 --- a/paperwork/templates/paperwork/email/member_certifications.dj.html +++ b/paperwork/templates/paperwork/email/member_certifications.dj.html @@ -12,7 +12,7 @@ {% for certification in certifications %} - {{ certification.certification_version.definition.certification_name }} + {{ certification.certification_version.definition.name }} {{ certification.certification_version.semantic_version }} {{ certification.certification_version.definition.department }} {{ certification.certified_by }} diff --git a/paperwork/templates/paperwork/member_certifications.dj.html b/paperwork/templates/paperwork/member_certifications.dj.html index 4a181f7..9f545db 100644 --- a/paperwork/templates/paperwork/member_certifications.dj.html +++ b/paperwork/templates/paperwork/member_certifications.dj.html @@ -27,7 +27,7 @@ {% if current or show_outdated %} - {{ certification.certification_version.definition.certification_name }} + {{ certification.certification_version.definition.name }} {{ certification.certification_version.semantic_version }}