Skip to content

Commit

Permalink
indexes
Browse files Browse the repository at this point in the history
  • Loading branch information
erikvw committed Dec 4, 2023
1 parent f3e9b0a commit b456eea
Show file tree
Hide file tree
Showing 6 changed files with 274 additions and 17 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,233 @@
# Generated by Django 4.2.7 on 2023-12-04 22:35

from django.db import migrations, models


class Migration(migrations.Migration):
dependencies = [
("edc_action_item", "0034_alter_actionitem_device_created_and_more"),
]

operations = [
migrations.AlterModelOptions(
name="actionitem",
options={
"default_manager_name": "objects",
"default_permissions": ("add", "change", "delete", "view", "export", "import"),
"verbose_name": "Action Item",
"verbose_name_plural": "Action Items",
},
),
migrations.AlterModelOptions(
name="actiontype",
options={
"default_manager_name": "objects",
"default_permissions": ("add", "change", "delete", "view", "export", "import"),
},
),
migrations.AlterModelOptions(
name="reference",
options={
"default_manager_name": "objects",
"default_permissions": ("add", "change", "delete", "view", "export", "import"),
},
),
migrations.RemoveIndex(
model_name="actionitem",
name="edc_action__id_6cb4e0_idx",
),
migrations.AddField(
model_name="actionitem",
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="actionitem",
name="locale_modified",
field=models.CharField(
blank=True,
help_text="Auto-updated by Modeladmin",
max_length=10,
null=True,
verbose_name="Locale modified",
),
),
migrations.AddField(
model_name="actiontype",
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="actiontype",
name="locale_modified",
field=models.CharField(
blank=True,
help_text="Auto-updated by Modeladmin",
max_length=10,
null=True,
verbose_name="Locale modified",
),
),
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",
),
),
migrations.AddField(
model_name="historicalactionitem",
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="historicalactionitem",
name="locale_modified",
field=models.CharField(
blank=True,
help_text="Auto-updated by Modeladmin",
max_length=10,
null=True,
verbose_name="Locale modified",
),
),
migrations.AddField(
model_name="historicalreference",
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="historicalreference",
name="locale_modified",
field=models.CharField(
blank=True,
help_text="Auto-updated by Modeladmin",
max_length=10,
null=True,
verbose_name="Locale modified",
),
),
migrations.AddField(
model_name="reference",
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="reference",
name="locale_modified",
field=models.CharField(
blank=True,
help_text="Auto-updated by Modeladmin",
max_length=10,
null=True,
verbose_name="Locale modified",
),
),
migrations.AddIndex(
model_name="actionitem",
index=models.Index(
fields=["modified", "created"], name="edc_action__modifie_d8a9b7_idx"
),
),
migrations.AddIndex(
model_name="actionitem",
index=models.Index(
fields=["user_modified", "user_created"], name="edc_action__user_mo_b01b34_idx"
),
),
migrations.AddIndex(
model_name="actionitem",
index=models.Index(
fields=["subject_identifier"], name="edc_action__subject_0dae34_idx"
),
),
migrations.AddIndex(
model_name="actionitem",
index=models.Index(
fields=[
"subject_identifier",
"action_identifier",
"action_type",
"site_id",
"status",
"report_datetime",
],
name="edc_action__subject_5bacf2_idx",
),
),
migrations.AddIndex(
model_name="actiontype",
index=models.Index(
fields=["modified", "created"], name="edc_action__modifie_7ecb65_idx"
),
),
migrations.AddIndex(
model_name="actiontype",
index=models.Index(
fields=["user_modified", "user_created"], name="edc_action__user_mo_62771e_idx"
),
),
migrations.AddIndex(
model_name="reference",
index=models.Index(
fields=["modified", "created"], name="edc_action__modifie_17f7a2_idx"
),
),
migrations.AddIndex(
model_name="reference",
index=models.Index(
fields=["user_modified", "user_created"], name="edc_action__user_mo_e27ce1_idx"
),
),
migrations.AddIndex(
model_name="reference",
index=models.Index(
fields=["subject_identifier"], name="edc_action__subject_b074e8_idx"
),
),
]
32 changes: 20 additions & 12 deletions edc_action_item/models/action_item.py
Original file line number Diff line number Diff line change
Expand Up @@ -222,17 +222,25 @@ def identifier(self) -> str:
"""Returns a shortened action identifier."""
return self.action_identifier[-9:]

class Meta(BaseUuidModel.Meta):
class Meta(
BaseUuidModel.Meta,
NonUniqueSubjectIdentifierFieldMixin.Meta,
):
verbose_name = "Action Item"
verbose_name_plural = "Action Items"
indexes = [
models.Index(
fields=[
"id",
"action_identifier",
"action_type",
"status",
"report_datetime",
]
)
]
indexes = (
BaseUuidModel.Meta.indexes
+ NonUniqueSubjectIdentifierFieldMixin.Meta.indexes
+ [
models.Index(
fields=[
"subject_identifier",
"action_identifier",
"action_type",
"site_id",
"status",
"report_datetime",
],
),
]
)
12 changes: 11 additions & 1 deletion edc_action_item/models/action_model_mixin.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,12 +122,22 @@ def identifier(self):

class Meta:
abstract = True
indexes = [
models.Index(
fields=[
"action_identifier",
"action_item",
"related_action_item",
"parent_action_item",
]
)
]


class ActionModelMixin(ActionNoManagersModelMixin):
objects = ActionIdentifierModelManager()

history = HistoricalRecords(inherit=True)

class Meta:
class Meta(ActionNoManagersModelMixin.Meta):
abstract = True
5 changes: 3 additions & 2 deletions edc_action_item/models/action_type.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ def save(self, *args, **kwargs):
super().save(*args, **kwargs)

class Meta(BaseUuidModel.Meta):
ordering = ["name"]
indexes = [models.Index(fields=["id", "name"])]
indexes = BaseUuidModel.Meta.indexes + [
models.Index(fields=["id", "name"]),
]
default_permissions = ("add", "change", "delete", "view", "export", "import")
6 changes: 4 additions & 2 deletions edc_action_item/models/reference.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,5 +35,7 @@ class Reference(NonUniqueSubjectIdentifierFieldMixin, ActionModelMixin, BaseUuid
def natural_key(self):
return (self.action_identifier,) # noqa

class Meta(BaseUuidModel.Meta):
pass
class Meta(BaseUuidModel.Meta, NonUniqueSubjectIdentifierFieldMixin.Meta):
indexes = (
BaseUuidModel.Meta.indexes + NonUniqueSubjectIdentifierFieldMixin.Meta.indexes
)
3 changes: 3 additions & 0 deletions edc_action_item/tests/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ class SubjectIdentifierModel(NonUniqueSubjectIdentifierFieldMixin, BaseUuidModel
def natural_key(self):
return (self.subject_identifier,) # noqa

class Meta(BaseUuidModel.Meta, NonUniqueSubjectIdentifierFieldMixin.Meta):
pass


class TestModelWithoutMixin(BaseUuidModel):
subject_identifier = models.CharField(max_length=25)
Expand Down

0 comments on commit b456eea

Please sign in to comment.