diff --git a/contracts/admin.py b/contracts/admin.py index b84ccc41dcabd6f6804b000aed4134a1e54a72f3..9e6b1b2cb26a230c2bb9434be1836f32a0858db1 100644 --- a/contracts/admin.py +++ b/contracts/admin.py @@ -5,18 +5,26 @@ from django.contrib import admin from django.contrib.auth.models import Permission from django.utils.html import format_html from import_export import resources -from nested_admin import (NestedModelAdmin, NestedStackedInline, - NestedTabularInline) +from nested_admin import NestedModelAdmin, NestedStackedInline, NestedTabularInline from rangefilter.filters import DateRangeFilter from shared.admin import FieldsetInlineOrder, MarkdownxGuardedModelAdmin from .forms import ContractAdminForm, ContractFileAdminForm, SigneeAdminForm -from .models import (Contract, Contractee, ContracteeSignature, - ContracteeSignatureRepresentative, ContractFile, - ContractFilingArea, ContractIntent, ContractIssue, - ContractType, Signee, SigneeSignature, - SigneeSignatureRepresentative) +from .models import ( + Contract, + Contractee, + ContracteeSignature, + ContracteeSignatureRepresentative, + ContractFile, + ContractFilingArea, + ContractIntent, + ContractIssue, + ContractType, + Signee, + SigneeSignature, + SigneeSignatureRepresentative, +) class ContractResource(resources.ModelResource): @@ -153,10 +161,16 @@ class ContractAdmin( ): form = ContractAdminForm - ordering = ("created_on", "name",) + ordering = ( + "created_on", + "name", + ) search_fields = ("name",) - readonly_fields = ("created_by", "created_on",) + readonly_fields = ( + "created_by", + "created_on", + ) autocomplete_fields = ( "primary_contract", "types", diff --git a/contracts/migrations/0019_contract_created_on.py b/contracts/migrations/0019_contract_created_on.py index ae8162dc8646d44afa4682b290b3eb17e04a81f8..3fbdb2f6670714bdb7e9e9c9a14a2e0051b1c847 100644 --- a/contracts/migrations/0019_contract_created_on.py +++ b/contracts/migrations/0019_contract_created_on.py @@ -1,19 +1,21 @@ # Generated by Django 4.1.4 on 2023-03-30 08:35 import datetime + from django.db import migrations, models class Migration(migrations.Migration): - dependencies = [ - ('contracts', '0018_contractee_created_by_signee_created_by'), + ("contracts", "0018_contractee_created_by_signee_created_by"), ] operations = [ migrations.AddField( - model_name='contract', - name='created_on', - field=models.DateTimeField(default=datetime.datetime.now, verbose_name='Čas vytvoření'), + model_name="contract", + name="created_on", + field=models.DateTimeField( + default=datetime.datetime.now, verbose_name="Čas vytvoření" + ), ), ] diff --git a/contracts/migrations/0020_alter_contract_created_on.py b/contracts/migrations/0020_alter_contract_created_on.py index 960aa5aa73f5a22b36c79f3a30958be38f9c16ec..b886252ad70de3972516dd07e9b22792e8a2e0d4 100644 --- a/contracts/migrations/0020_alter_contract_created_on.py +++ b/contracts/migrations/0020_alter_contract_created_on.py @@ -1,19 +1,22 @@ # Generated by Django 4.1.4 on 2023-03-30 08:36 -import contracts.models from django.db import migrations, models +import contracts.models + class Migration(migrations.Migration): - dependencies = [ - ('contracts', '0019_contract_created_on'), + ("contracts", "0019_contract_created_on"), ] operations = [ migrations.AlterField( - model_name='contract', - name='created_on', - field=models.DateTimeField(default=contracts.models.get_created_on_timestamp, verbose_name='Čas vytvoření'), + model_name="contract", + name="created_on", + field=models.DateTimeField( + default=contracts.models.get_created_on_timestamp, + verbose_name="Čas vytvoření", + ), ), ] diff --git a/contracts/migrations/0021_contract_updated_on_alter_contractee_address_country_and_more.py b/contracts/migrations/0021_contract_updated_on_alter_contractee_address_country_and_more.py new file mode 100644 index 0000000000000000000000000000000000000000..aea8b86c860d1df59617e262bee0881c52244c4c --- /dev/null +++ b/contracts/migrations/0021_contract_updated_on_alter_contractee_address_country_and_more.py @@ -0,0 +1,36 @@ +# Generated by Django 4.1.4 on 2023-03-30 09:42 + +from django.db import migrations, models + +import contracts.models + + +class Migration(migrations.Migration): + dependencies = [ + ("contracts", "0020_alter_contract_created_on"), + ] + + operations = [ + migrations.AddField( + model_name="contract", + name="updated_on", + field=models.DateTimeField( + default=contracts.models.get_current_utc_timestamp, + verbose_name="Čas poslední aktualizace", + ), + ), + migrations.AlterField( + model_name="contractee", + name="address_country", + field=models.CharField( + default="Česká Republika", max_length=256, verbose_name="Země" + ), + ), + migrations.AlterField( + model_name="signee", + name="address_country", + field=models.CharField( + default="Česká Republika", max_length=256, verbose_name="Země" + ), + ), + ] diff --git a/contracts/models.py b/contracts/models.py index 79506265877a7e23ded54770d169a5600437a236..eedfe6df006d14d5896328e26a80c07d6c7cfdea 100644 --- a/contracts/models.py +++ b/contracts/models.py @@ -318,10 +318,14 @@ class ContractFilingArea(ContractCountMixin, NameStrMixin, models.Model): verbose_name_plural = "Spisovny" -def get_created_on_timestamp(): +def get_current_utc_timestamp(): return datetime.datetime.now(datetime.timezone.utc) +# Pre-squash migration compatibility +get_created_on_timestamp = get_current_utc_timestamp + + class Contract(NameStrMixin, models.Model): # BEGIN Automatically set fields @@ -338,9 +342,15 @@ class Contract(NameStrMixin, models.Model): created_on = models.DateTimeField( blank=False, null=False, - default=get_created_on_timestamp, + default=get_current_utc_timestamp, verbose_name="Čas vytvoření", ) + updated_on = models.DateTimeField( + blank=False, + null=False, + default=get_current_utc_timestamp, + verbose_name="Čas poslední aktualizace", + ) public_status_set_by = models.ForeignKey( User, @@ -586,6 +596,11 @@ class Contract(NameStrMixin, models.Model): } ) + def save(self, *args, **kwargs): + self.updated_on = get_current_utc_timestamp() + + return super().save(*args, **kwargs) + class Meta: app_label = "contracts"