Fixes: (1) Removed all `# type: ignore` annotations across the codebase; (2) Fixed usage of Django Model methods by eliminating unnecessary `# type: ignore` directives; (3) Adjusted usage of functions like `get()` to align with method expectations, removing incorrect comments; Extra: (1) Deleted `pyrightconfig.json` as part of migration to a stricter type-checked environment; (2) Minor code cleanup, including formatting changes and refactoring import statements in adherence to PEP8 recommendations.
51 lines
1.5 KiB
Python
51 lines
1.5 KiB
Python
import uuid
|
|
from typing import Collection
|
|
|
|
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 = None
|
|
uuid = UUIDField(
|
|
verbose_name=_("unique id"),
|
|
help_text=_("unique id is used to surely identify any database object"),
|
|
primary_key=True,
|
|
default=uuid.uuid4,
|
|
editable=False,
|
|
)
|
|
is_active = BooleanField(
|
|
default=True,
|
|
verbose_name=_("is active"),
|
|
help_text=_(
|
|
"if set to false, this object can't be seen by users without needed permission"
|
|
),
|
|
)
|
|
created = CreationDateTimeField(
|
|
_("created"), help_text=_("when the object first appeared on the database")
|
|
)
|
|
modified = ModificationDateTimeField(
|
|
_("modified"), help_text=_("when the object was last modified")
|
|
)
|
|
|
|
def save(
|
|
self,
|
|
*,
|
|
force_insert: bool = False,
|
|
force_update: bool = False,
|
|
using: str | None = None,
|
|
update_fields: Collection[str] | None = None,
|
|
update_modified: bool = True,
|
|
) -> None:
|
|
self.update_modified = update_modified
|
|
return super().save(
|
|
force_insert=force_insert,
|
|
force_update=force_update,
|
|
using=using,
|
|
update_fields=update_fields,
|
|
)
|
|
|
|
class Meta:
|
|
abstract = True
|
|
get_latest_by = "modified"
|