From bbd3d0e47002a1a6872f5c6dcf07ea172606535a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=BE=9D=E7=91=AA=E8=B2=93?= Date: Sun, 9 Aug 2020 16:34:47 +0800 Subject: [PATCH] Revised and simplify the data model definition. --- accounting/models.py | 34 ++++++++++------------------------ mia_core/models.py | 4 ++-- 2 files changed, 12 insertions(+), 26 deletions(-) diff --git a/accounting/models.py b/accounting/models.py index 3a8463a..3b03e45 100644 --- a/accounting/models.py +++ b/accounting/models.py @@ -32,25 +32,19 @@ class Account(DirtyFieldsMixin, models.Model): """An account.""" id = models.PositiveIntegerField(primary_key=True) parent = models.ForeignKey( - "self", on_delete=models.PROTECT, null=True, blank=True, + "self", on_delete=models.PROTECT, null=True, related_name="child_set") code = models.CharField(max_length=5, unique=True) - title_zh_hant = models.CharField( - max_length=32, db_column="title_zhtw") - title_en = models.CharField(max_length=128, null=True, blank=True) - title_zh_hans = models.CharField( - max_length=32, null=True, blank=True, db_column="title_zhcn") - created_at = models.DateTimeField( - auto_now_add=True, db_column="created") + title_zh_hant = models.CharField(max_length=32) + title_en = models.CharField(max_length=128, null=True) + title_zh_hans = models.CharField(max_length=32, null=True) + created_at = models.DateTimeField(auto_now_add=True) created_by = models.ForeignKey( settings.AUTH_USER_MODEL, on_delete=models.PROTECT, - db_column="createdby", related_name="created_accounting_accounts") - updated_at = models.DateTimeField( - auto_now_add=True, db_column="updated") + updated_at = models.DateTimeField(auto_now=True) updated_by = models.ForeignKey( settings.AUTH_USER_MODEL, on_delete=models.PROTECT, - db_column="updatedby", related_name="updated_accounting_accounts") CASH = "1111" ACCUMULATED_BALANCE = "3351" @@ -142,17 +136,13 @@ class Transaction(DirtyFieldsMixin, models.Model): date = models.DateField() ord = models.PositiveSmallIntegerField(default=1) notes = models.CharField(max_length=128, null=True, blank=True) - created_at = models.DateTimeField( - auto_now_add=True, db_column="created") + created_at = models.DateTimeField(auto_now_add=True) created_by = models.ForeignKey( settings.AUTH_USER_MODEL, on_delete=models.PROTECT, - db_column="createdby", related_name="created_accounting_transactions") - updated_at = models.DateTimeField( - auto_now_add=True, db_column="updated") + updated_at = models.DateTimeField(auto_now=True) updated_by = models.ForeignKey( settings.AUTH_USER_MODEL, on_delete=models.PROTECT, - db_column="updatedby", related_name="updated_accounting_transactions") def __init__(self, *args, **kwargs): @@ -369,17 +359,13 @@ class Record(DirtyFieldsMixin, models.Model): Account, on_delete=models.PROTECT) summary = models.CharField(max_length=128, blank=True, null=True) amount = models.PositiveIntegerField() - created_at = models.DateTimeField( - auto_now_add=True, db_column="created") + created_at = models.DateTimeField(auto_now_add=True) created_by = models.ForeignKey( settings.AUTH_USER_MODEL, on_delete=models.PROTECT, - db_column="createdby", related_name="created_accounting_records") - updated_at = models.DateTimeField( - auto_now_add=True, db_column="updated") + updated_at = models.DateTimeField(auto_now=True) updated_by = models.ForeignKey( settings.AUTH_USER_MODEL, on_delete=models.PROTECT, - db_column="updatedby", related_name="updated_accounting_records") def __init__(self, *args, **kwargs): diff --git a/mia_core/models.py b/mia_core/models.py index e2a4a57..451529a 100644 --- a/mia_core/models.py +++ b/mia_core/models.py @@ -41,7 +41,7 @@ class Country(DirtyFieldsMixin, models.Model): "User", on_delete=models.PROTECT, db_column="createdby", related_name="created_countries") updated_at = models.DateTimeField( - auto_now_add=True, db_column="updated") + auto_now=True, db_column="updated") updated_by = models.ForeignKey( "User", on_delete=models.PROTECT, db_column="updatedby", related_name="updated_countries") @@ -87,7 +87,7 @@ class User(DirtyFieldsMixin, models.Model): "self", on_delete=models.PROTECT, db_column="createdby", related_name="created_users") updated_at = models.DateTimeField( - auto_now_add=True, db_column="updated") + auto_now=True, db_column="updated") updated_by = models.ForeignKey( "self", on_delete=models.PROTECT, db_column="updatedby", related_name="updated_users")