Merge pull request #13 from sadman59m/refactor/SRI-454-django-project-structure

Refactor/sri 454 django project structure
This commit is contained in:
Saqibur Rahman 2024-03-08 19:05:20 +06:00 committed by GitHub
commit 0fe837362b
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 85 additions and 73 deletions

View File

@ -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

1
common/constants.py Normal file
View File

@ -0,0 +1 @@
# Add your common constants here that are common for all other apps.

0
common/helpers.py Normal file
View File

84
common/models.py Normal file
View File

@ -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