diff --git a/contracts/admin.py b/contracts/admin.py index 40623f0582bbe5f36ae6bbd8b1a8f0cd7f4ab945..864fb13116bd9346c3a82dbfe76f2a384e2b3fc5 100644 --- a/contracts/admin.py +++ b/contracts/admin.py @@ -70,7 +70,7 @@ class OwnPermissionsMixin( lambda request, obj: obj.created_by != request.user, ) ): - def own_permissions_mixin_save_model(self, request, obj, form, change): + def save_model(self, request, obj, form, change): if obj.created_by is None: obj.created_by = request.user @@ -153,10 +153,10 @@ class ContractAdmin( ): form = ContractAdminForm - ordering = ("name",) + ordering = ("created_on", "name",) search_fields = ("name",) - readonly_fields = ("created_by",) + readonly_fields = ("created_by", "created_on",) autocomplete_fields = ( "primary_contract", "types", @@ -235,6 +235,8 @@ class ContractAdmin( "fields": [ "issues", "notes", + "created_by", + "created_on", ] }, ), diff --git a/contracts/migrations/0019_contract_created_on.py b/contracts/migrations/0019_contract_created_on.py new file mode 100644 index 0000000000000000000000000000000000000000..ae8162dc8646d44afa4682b290b3eb17e04a81f8 --- /dev/null +++ b/contracts/migrations/0019_contract_created_on.py @@ -0,0 +1,19 @@ +# 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'), + ] + + operations = [ + migrations.AddField( + 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 new file mode 100644 index 0000000000000000000000000000000000000000..960aa5aa73f5a22b36c79f3a30958be38f9c16ec --- /dev/null +++ b/contracts/migrations/0020_alter_contract_created_on.py @@ -0,0 +1,19 @@ +# Generated by Django 4.1.4 on 2023-03-30 08:36 + +import contracts.models +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('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í'), + ), + ] diff --git a/contracts/models.py b/contracts/models.py index 1e5cb1f5e89f0a9e25736335e90f2ed8ca471119..79506265877a7e23ded54770d169a5600437a236 100644 --- a/contracts/models.py +++ b/contracts/models.py @@ -1,3 +1,4 @@ +import datetime import typing from django.conf import settings @@ -317,6 +318,10 @@ class ContractFilingArea(ContractCountMixin, NameStrMixin, models.Model): verbose_name_plural = "Spisovny" +def get_created_on_timestamp(): + return datetime.datetime.now(datetime.timezone.utc) + + class Contract(NameStrMixin, models.Model): # BEGIN Automatically set fields @@ -330,6 +335,13 @@ class Contract(NameStrMixin, models.Model): help_text="Informace není veřejně přístupná. Pokud vytváříš novou smlouvu, budeš to ty.", ) # WARNING: exclude in admin + created_on = models.DateTimeField( + blank=False, + null=False, + default=get_created_on_timestamp, + verbose_name="Čas vytvoření", + ) + public_status_set_by = models.ForeignKey( User, on_delete=models.SET_NULL,