From bdaee51e83509ed8d7bd6381ca847152c4e0142a Mon Sep 17 00:00:00 2001 From: Sadman Sakib Date: Fri, 8 Mar 2024 15:41:25 +0600 Subject: [PATCH 1/5] refactor: moved common constants.py file from core app to common app --- common/constants.py | 0 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 common/constants.py diff --git a/common/constants.py b/common/constants.py new file mode 100644 index 0000000..e69de29 From 4db6184bfc5636579d99d42bdf3ff6ec1a4f7d29 Mon Sep 17 00:00:00 2001 From: Sadman Sakib Date: Fri, 8 Mar 2024 17:53:04 +0600 Subject: [PATCH 2/5] feat: added constants.py in the common app that are common for all othre apps: --- common/constants.py | 1 + 1 file changed, 1 insertion(+) diff --git a/common/constants.py b/common/constants.py index e69de29..7f37291 100644 --- a/common/constants.py +++ b/common/constants.py @@ -0,0 +1 @@ +# Add your common constants here that are common for all other apps. \ No newline at end of file From 4de8b100d0bdf184868ab583daf2b9c3b13134ec Mon Sep 17 00:00:00 2001 From: Sadman Sakib Date: Fri, 8 Mar 2024 17:53:37 +0600 Subject: [PATCH 3/5] feat: added common helpers.py file --- common/helpers.py | 0 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 common/helpers.py diff --git a/common/helpers.py b/common/helpers.py new file mode 100644 index 0000000..e69de29 From ba0e83ca9c4987ec68d1ff6f83ebc39305339d15 Mon Sep 17 00:00:00 2001 From: Sadman Sakib Date: Fri, 8 Mar 2024 17:54:14 +0600 Subject: [PATCH 4/5] feat: added models.py file and moved BaseModel in here --- common/models.py | 84 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 84 insertions(+) create mode 100644 common/models.py diff --git a/common/models.py b/common/models.py new file mode 100644 index 0000000..49854e1 --- /dev/null +++ b/common/models.py @@ -0,0 +1,84 @@ +# Standard library imports +import uuid + +# Django imports +from django.conf import settings +from django.db import models +from django.utils.translation import gettext_lazy as _ + +# Django Rest Framework imports + +# Third party imports + +# Local imports + +user_model = settings.AUTH_USER_MODEL + + +class IsDeletedManager(models.Manager): + def get_queryset(self): + return super().get_queryset().filter(is_deleted=False) + + +class BaseModel(models.Model): + """ + Tracks instance creations, updates, and (soft) deletions. + """ + + uuid = models.UUIDField( + verbose_name=_("UUID"), unique=True, default=uuid.uuid4, editable=False + ) + + created_by = models.ForeignKey( + to=user_model, + verbose_name=_("Created by"), + null=True, + blank=True, + related_name="%(class)s_created", + on_delete=models.SET_NULL, + ) + + created_at = models.DateTimeField( + verbose_name=_("Created at"), + auto_now_add=True, + editable=False, + db_index=True, + ) + + updated_by = models.ForeignKey( + to=user_model, + verbose_name=_("Updated by"), + null=True, + blank=True, + related_name="%(class)s_updated", + on_delete=models.SET_NULL, + ) + + updated_at = models.DateTimeField( + verbose_name=_("Updated at"), + auto_now=True, + null=True, + blank=True, + ) + + deleted_by = models.ForeignKey( + to=user_model, + verbose_name=_("Deleted by"), + null=True, + blank=True, + related_name="%(class)s_deleted", + on_delete=models.SET_NULL, + ) + + deleted_at = models.DateTimeField( + verbose_name=_("Deleted at"), null=True, blank=True, default=None + ) + + is_deleted = models.BooleanField(verbose_name=_("Is deleted"), default=False) + + objects = IsDeletedManager() + + objects_all = models.Manager() + + class Meta: + abstract = True From b7457b305617b0a63dcf74040c5ab0646085ebf6 Mon Sep 17 00:00:00 2001 From: Sadman Sakib Date: Fri, 8 Mar 2024 17:55:21 +0600 Subject: [PATCH 5/5] refactor: moved BaseModel to the common app --- apps/core/models.py | 73 --------------------------------------------- 1 file changed, 73 deletions(-) diff --git a/apps/core/models.py b/apps/core/models.py index f3c4bb5..e69de29 100644 --- a/apps/core/models.py +++ b/apps/core/models.py @@ -1,73 +0,0 @@ -import uuid - -from django.conf import settings -from django.db import models -from django.utils.translation import gettext_lazy as _ - -user_model = settings.AUTH_USER_MODEL - - - -class IsDeletedManager(models.Manager): - def get_queryset(self): - return super().get_queryset().filter(is_deleted=False) - - - -class BaseModel(models.Model): - """ - Tracks instance creations, updates, and (soft) deletions. - """ - - uid = models.UUIDField( - verbose_name=_("UUID"), unique=True, default=uuid.uuid4, editable=False - ) - - created_by = models.ForeignKey( - to=user_model, - verbose_name=_("Created by"), - null=True, - blank=True, - related_name="%(class)s_created", - on_delete=models.SET_NULL, - ) - - created_at = models.DateTimeField( - verbose_name=_("Created at"), - auto_now_add=True, - editable=False, - db_index=True, - ) - - updated_by = models.ForeignKey( - to=user_model, - verbose_name=_("Updated by"), - null=True, - blank=True, - related_name="%(class)s_updated", - on_delete=models.SET_NULL, - ) - - updated_at = models.DateTimeField( - verbose_name=_("Updated at"), auto_now=True, null=True, blank=True - ) - - deleted_by = models.ForeignKey( - to=user_model, - verbose_name=_("Deleted by"), - null=True, - blank=True, - related_name="%(class)s_deleted", - on_delete=models.SET_NULL, - ) - - deleted_at = models.DateTimeField(verbose_name=_("Deleted at"), null=True, blank=True) - - is_deleted = models.BooleanField(verbose_name=_("Is deleted"), default=False) - - objects = IsDeletedManager() - - objects_all = models.Manager() - - class Meta: - abstract = True