From 73e8fdbf04cefa858b1c0f8fbf36255b47ccda5e Mon Sep 17 00:00:00 2001 From: Herculino Trotta Date: Sun, 9 Mar 2025 18:55:29 -0300 Subject: [PATCH] feat: alphabetically order most models by default #207 --- ...ount_options_alter_accountgroup_options.py | 21 ++++++++++++++++ app/apps/accounts/models.py | 2 ++ .../migrations/0014_alter_currency_options.py | 17 +++++++++++++ app/apps/currencies/models.py | 1 + .../mini_tools/utils/exchange_rate_map.py | 2 +- ...er_transactioncategory_options_and_more.py | 25 +++++++++++++++++++ app/apps/transactions/models.py | 3 +++ 7 files changed, 70 insertions(+), 1 deletion(-) create mode 100644 app/apps/accounts/migrations/0014_alter_account_options_alter_accountgroup_options.py create mode 100644 app/apps/currencies/migrations/0014_alter_currency_options.py create mode 100644 app/apps/transactions/migrations/0042_alter_transactioncategory_options_and_more.py diff --git a/app/apps/accounts/migrations/0014_alter_account_options_alter_accountgroup_options.py b/app/apps/accounts/migrations/0014_alter_account_options_alter_accountgroup_options.py new file mode 100644 index 0000000..cf146dc --- /dev/null +++ b/app/apps/accounts/migrations/0014_alter_account_options_alter_accountgroup_options.py @@ -0,0 +1,21 @@ +# Generated by Django 5.1.7 on 2025-03-09 21:54 + +from django.db import migrations + + +class Migration(migrations.Migration): + + dependencies = [ + ('accounts', '0013_alter_account_visibility_and_more'), + ] + + operations = [ + migrations.AlterModelOptions( + name='account', + options={'ordering': ['name', 'id'], 'verbose_name': 'Account', 'verbose_name_plural': 'Accounts'}, + ), + migrations.AlterModelOptions( + name='accountgroup', + options={'ordering': ['name', 'id'], 'verbose_name': 'Account Group', 'verbose_name_plural': 'Account Groups'}, + ), + ] diff --git a/app/apps/accounts/models.py b/app/apps/accounts/models.py index ae3bc7c..e6efbc8 100644 --- a/app/apps/accounts/models.py +++ b/app/apps/accounts/models.py @@ -19,6 +19,7 @@ class AccountGroup(SharedObject): verbose_name_plural = _("Account Groups") db_table = "account_groups" unique_together = (("owner", "name"),) + ordering = ["name", "id"] def __str__(self): return self.name @@ -69,6 +70,7 @@ class Account(SharedObject): verbose_name = _("Account") verbose_name_plural = _("Accounts") unique_together = (("owner", "name"),) + ordering = ["name", "id"] def __str__(self): return self.name diff --git a/app/apps/currencies/migrations/0014_alter_currency_options.py b/app/apps/currencies/migrations/0014_alter_currency_options.py new file mode 100644 index 0000000..bdd074f --- /dev/null +++ b/app/apps/currencies/migrations/0014_alter_currency_options.py @@ -0,0 +1,17 @@ +# Generated by Django 5.1.7 on 2025-03-09 21:54 + +from django.db import migrations + + +class Migration(migrations.Migration): + + dependencies = [ + ('currencies', '0013_alter_exchangerateservice_service_type'), + ] + + operations = [ + migrations.AlterModelOptions( + name='currency', + options={'ordering': ['name', 'id'], 'verbose_name': 'Currency', 'verbose_name_plural': 'Currencies'}, + ), + ] diff --git a/app/apps/currencies/models.py b/app/apps/currencies/models.py index e4f3281..234af36 100644 --- a/app/apps/currencies/models.py +++ b/app/apps/currencies/models.py @@ -38,6 +38,7 @@ class Currency(models.Model): class Meta: verbose_name = _("Currency") verbose_name_plural = _("Currencies") + ordering = ["name", "id"] def clean(self): super().clean() diff --git a/app/apps/mini_tools/utils/exchange_rate_map.py b/app/apps/mini_tools/utils/exchange_rate_map.py index 0624517..9b44cb2 100644 --- a/app/apps/mini_tools/utils/exchange_rate_map.py +++ b/app/apps/mini_tools/utils/exchange_rate_map.py @@ -41,7 +41,7 @@ def get_currency_exchange_map(date=None) -> Dict[str, dict]: effective_rate=F("rate"), ) .order_by("from_currency", "to_currency", "date_diff") - .distinct("from_currency", "to_currency") + .distinct() ) # Initialize the result dictionary diff --git a/app/apps/transactions/migrations/0042_alter_transactioncategory_options_and_more.py b/app/apps/transactions/migrations/0042_alter_transactioncategory_options_and_more.py new file mode 100644 index 0000000..b83c03f --- /dev/null +++ b/app/apps/transactions/migrations/0042_alter_transactioncategory_options_and_more.py @@ -0,0 +1,25 @@ +# Generated by Django 5.1.7 on 2025-03-09 21:54 + +from django.db import migrations + + +class Migration(migrations.Migration): + + dependencies = [ + ('transactions', '0041_installmentplan_add_description_to_transaction_and_more'), + ] + + operations = [ + migrations.AlterModelOptions( + name='transactioncategory', + options={'ordering': ['name', 'id'], 'verbose_name': 'Transaction Category', 'verbose_name_plural': 'Transaction Categories'}, + ), + migrations.AlterModelOptions( + name='transactionentity', + options={'ordering': ['name', 'id'], 'verbose_name': 'Entity', 'verbose_name_plural': 'Entities'}, + ), + migrations.AlterModelOptions( + name='transactiontag', + options={'ordering': ['name', 'id'], 'verbose_name': 'Transaction Tags', 'verbose_name_plural': 'Transaction Tags'}, + ), + ] diff --git a/app/apps/transactions/models.py b/app/apps/transactions/models.py index 0fd215b..d3114bb 100644 --- a/app/apps/transactions/models.py +++ b/app/apps/transactions/models.py @@ -213,6 +213,7 @@ class TransactionCategory(SharedObject): verbose_name_plural = _("Transaction Categories") db_table = "t_categories" unique_together = (("owner", "name"),) + ordering = ["name", "id"] def __str__(self): return self.name @@ -236,6 +237,7 @@ class TransactionTag(SharedObject): verbose_name_plural = _("Transaction Tags") db_table = "tags" unique_together = (("owner", "name"),) + ordering = ["name", "id"] def __str__(self): return self.name @@ -259,6 +261,7 @@ class TransactionEntity(SharedObject): verbose_name_plural = _("Entities") db_table = "entities" unique_together = (("owner", "name"),) + ordering = ["name", "id"] def __str__(self): return self.name