diff --git a/edc_consent/migrations/0003_edcpermissions_locale_created_and_more.py b/edc_consent/migrations/0003_edcpermissions_locale_created_and_more.py new file mode 100644 index 0000000..3da353e --- /dev/null +++ b/edc_consent/migrations/0003_edcpermissions_locale_created_and_more.py @@ -0,0 +1,34 @@ +# Generated by Django 4.2.7 on 2023-12-01 14:47 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + dependencies = [ + ("edc_consent", "0002_alter_edcpermissions_device_created_and_more"), + ] + + operations = [ + migrations.AddField( + model_name="edcpermissions", + name="locale_created", + field=models.CharField( + blank=True, + help_text="Auto-updated by Modeladmin", + max_length=10, + null=True, + verbose_name="Locale created", + ), + ), + migrations.AddField( + model_name="edcpermissions", + name="locale_modified", + field=models.CharField( + blank=True, + help_text="Auto-updated by Modeladmin", + max_length=10, + null=True, + verbose_name="Locale modified", + ), + ), + ] diff --git a/edc_consent/migrations/0004_alter_edcpermissions_options_and_more.py b/edc_consent/migrations/0004_alter_edcpermissions_options_and_more.py new file mode 100644 index 0000000..1377c6d --- /dev/null +++ b/edc_consent/migrations/0004_alter_edcpermissions_options_and_more.py @@ -0,0 +1,41 @@ +# Generated by Django 4.2.7 on 2023-12-04 22:19 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + dependencies = [ + ("edc_consent", "0003_edcpermissions_locale_created_and_more"), + ] + + operations = [ + migrations.AlterModelOptions( + name="edcpermissions", + options={ + "default_manager_name": "objects", + "default_permissions": ( + "add", + "change", + "delete", + "view", + "export", + "import", + ), + "verbose_name": "Edc Permissions", + "verbose_name_plural": "Edc Permissions", + }, + ), + migrations.AddIndex( + model_name="edcpermissions", + index=models.Index( + fields=["modified", "created"], name="edc_consent_modifie_851b6a_idx" + ), + ), + migrations.AddIndex( + model_name="edcpermissions", + index=models.Index( + fields=["user_modified", "user_created"], + name="edc_consent_user_mo_27c64b_idx", + ), + ), + ] diff --git a/edc_consent/model_mixins/consent_model_mixin.py b/edc_consent/model_mixins/consent_model_mixin.py index e6ee722..03313e7 100644 --- a/edc_consent/model_mixins/consent_model_mixin.py +++ b/edc_consent/model_mixins/consent_model_mixin.py @@ -1,7 +1,7 @@ from uuid import uuid4 from django.db import models -from django.db.models import options +from django.db.models import UniqueConstraint, options from django_crypto_fields.fields import EncryptedTextField from edc_constants.constants import OPEN from edc_data_manager.get_data_queries import get_data_queries @@ -148,21 +148,26 @@ class Meta: verbose_name = "Subject Consent" verbose_name_plural = "Subject Consents" consent_group = DEFAULT_CONSENT_GROUP - get_latest_by = "consent_datetime" - unique_together = ( - ("first_name", "dob", "initials", "version"), - ("subject_identifier", "version"), - ) - ordering = ("created",) - - indexes = [ - models.Index( + constraints = [ + UniqueConstraint( + fields=["first_name", "dob", "initials", "version"], + name="%(app_label)s_%(class)s_first_uniq", + ), + UniqueConstraint( fields=[ "subject_identifier", "first_name", "dob", "initials", "version", - ] - ) + ], + name="%(app_label)s_%(class)s_subject_uniq", + ), + UniqueConstraint( + fields=[ + "version", + "subject_identifier", + ], + name="%(app_label)s_%(class)s_version_uniq", + ), ] diff --git a/edc_consent/models/edc_permissions.py b/edc_consent/models/edc_permissions.py index 8144613..c3f4c2d 100644 --- a/edc_consent/models/edc_permissions.py +++ b/edc_consent/models/edc_permissions.py @@ -5,5 +5,5 @@ class EdcPermissions(EdcPermissionsModelMixin, BaseUuidModel): # see edc_auth for permissions attached to this model - class Meta(EdcPermissionsModelMixin.Meta): - pass + class Meta(EdcPermissionsModelMixin.Meta, BaseUuidModel.Meta): + indexes = BaseUuidModel.Meta.indexes