common package
Submodules
common.base_model module
Healthy Meals Web Site Copyright (C) 2025 David A. Taylor of Taylored Web Sites (tayloredwebsites.com) Licensed under AGPL-3.0-only. See https://opensource.org/license/agpl-v3/
https://github.com/tayloredwebsites/healthy-meals - healthy_meals/base_model.py
- class common.base_model.BaseModel(*args, **kwargs)[source]
Bases:
SafeDeleteModelDatabase table:
NoneBaseModel is abstract class to base all models in this project
- has soft delete functionality included through django-safedelete
- has record history / versioning through django-auditlog
SOFT DELETE FUNCTIONALITY Note: The customized functions for soft deletion are only found in model manager classes Thus??: to use the methods found in ‘objects’, their models must declare their custom manager based off of SafeDeleteManager (This should be validated!!!) See: accounts/models.py for an example
all_with_deleted() # Show all model records including the soft deleted models.
deleted_only() # Only show the soft deleted model records.
all(**kwargs) -> django.db.models.query.QuerySet # Show deleted model records. (default: {None})
update_or_create(defaults=None, **kwargs) -> Tuple[django.db.models.base.Model, bool] # https://django-safedelete.readthedocs.io/en/latest/managers.html#safedelete.managers.SafeDeleteManager.update_or_create
AUDITLOG VERSIONING HISTORY FUNCTIONALITY - has record history / versioning through django-auditlog (https://github.com/jazzband/django-auditlog)
this provides the ability to see all of the changes to fields (except fields excluded when registered in the model)
see: https://django-auditlog.readthedocs.io/en/latest/usage.html
Note: To register auditlog to automatically log all changes to a model, it must be registered in the model To register auditlog, the last line of the model should have the auditlog.register statement. For Example (as can be seen in accounts/models.py):
- auditlog.register(CustomUser, exclude_fields=[
‘password’, # protect this field for security reasons ‘last_login’, # do not update audit log for each login ]
- Parameters:
deleted (DateTimeField) – Deleted
deleted_by_cascade (BooleanField) – Deleted by cascade
created_at (DateTimeField) – Created at
updated_at (DateTimeField) – Updated at
Relationship fields:
- Parameters:
history (
AuditlogHistoryFieldtoLogEntry) – History
- created_at
Type:
DateTimeFieldCreated at
A wrapper for a deferred-loading field. When the value is read from this
- deleted
Type:
DateTimeFieldDeleted
A wrapper for a deferred-loading field. When the value is read from this
- deleted_by_cascade
Type:
BooleanFieldDeleted by cascade
A wrapper for a deferred-loading field. When the value is read from this
- get_next_by_created_at(*, field=<django.db.models.DateTimeField: created_at>, is_next=True, **kwargs)
Finds next instance based on
created_at. Seeget_next_by_FOO()for more information.
- get_next_by_updated_at(*, field=<django.db.models.DateTimeField: updated_at>, is_next=True, **kwargs)
Finds next instance based on
updated_at. Seeget_next_by_FOO()for more information.
- get_previous_by_created_at(*, field=<django.db.models.DateTimeField: created_at>, is_next=False, **kwargs)
Finds previous instance based on
created_at. Seeget_previous_by_FOO()for more information.
- get_previous_by_updated_at(*, field=<django.db.models.DateTimeField: updated_at>, is_next=False, **kwargs)
Finds previous instance based on
updated_at. Seeget_previous_by_FOO()for more information.
- history
Type: Reverse
AuditlogHistoryFieldfromBaseModelAll + of this log entry
Accessor to the related objects manager on the one-to-many relation created by GenericRelation.
In the example:
class Post(Model): comments = GenericRelation(Comment)
- rec_history_field_changed(user_rec, field_name)[source]
Return the number of records that are maintained in CustomUser’s history table.
- rec_history_field_is_now(user_rec, field_name)[source]
Return the latest history record value for this field (should be identical to current field value)
- rec_history_field_was(user_rec, field_name)[source]
Return a dictionary of the previous values for this field, for this record.
- updated_at
Type:
DateTimeFieldUpdated at
A wrapper for a deferred-loading field. When the value is read from this