schon/core/abstract.py
Egor fureunoir Gorbunov 5425225e31 Features: 1) Add datetime library import; 2) Introduce id_for_label properties for all fields in NiceModel;
Fixes: 1) Correct field type hints and add `# type: ignore` to suppress validation issues;

Extra: Refactor code for formatting consistency and readability.
2025-06-22 15:54:43 +03:00

44 lines
1.4 KiB
Python

import uuid
from datetime import datetime
from django.db.models import BooleanField, Model, UUIDField
from django.utils.translation import gettext_lazy as _
from django_extensions.db.fields import CreationDateTimeField, ModificationDateTimeField
class NiceModel(Model):
id = None
uuid: uuid = UUIDField( # type: ignore
verbose_name=_("unique id"),
help_text=_("unique id is used to surely identify any database object"),
primary_key=True,
default=uuid.uuid4,
editable=False,
)
uuid.id_for_label = "uuid"
is_active: bool = BooleanField( # type: ignore
default=True,
verbose_name=_("is active"),
help_text=_(
"if set to false, this object can't be seen by users without needed permission"
),
)
is_active.id_for_label = "is_active"
created: datetime = CreationDateTimeField( # type: ignore
_("created"), help_text=_("when the object first appeared on the database")
)
created.id_for_label = "created"
modified: datetime = ModificationDateTimeField( # type: ignore
_("modified"), help_text=_("when the object was last modified")
)
modified.id_for_label = "modified"
def save(self, **kwargs):
self.update_modified = kwargs.pop(
"update_modified", getattr(self, "update_modified", True)
)
super().save(**kwargs)
class Meta:
abstract = True
get_latest_by = "modified"