Skip to content
Snippets Groups Projects
Verified Commit 3ec31d2f authored by Nik | Klampfradler's avatar Nik | Klampfradler
Browse files

Add created_by and updated_by properties

Advances #182.
parent 4cd5d27d
No related branches found
No related tags found
1 merge request!163Mandate use of AlekSIS base model
......@@ -69,21 +69,45 @@ class ExtensibleModel(CRUDMixin):
- Dominik George <dominik.george@teckids.org>
"""
@property
def crud_event_create(self) -> Optional[CRUDEvent]:
""" Return create event of this object """
return self.crud_events.filter(event_type=CRUDEvent.CREATE).latest("datetime")
@property
def crud_event_update(self) -> Optional[CRUDEvent]:
""" Return last event of this object """
return self.crud_events.latest("datetime")
@property
def created_at(self) -> Optional[datetime]:
""" Determine creation timestamp from CRUD log """
event = self.crud_events.filter(event_type=CRUDEvent.CREATE).latest("datetime")
if event:
return event.datetime
if self.crud_event_create:
return self.crud_event_create.datetime
@property
def updated_at(self) -> Optional[datetime]:
""" Determine last timestamp from CRUD log """
event = self.crud_events.latest("datetime")
if event:
return event.datetime
if self.crud_event_update:
return self.crud_event_update.datetime
extended_data = JSONField(default=dict, editable=False)
@property
def created_by(self) -> Optional[models.Model]:
""" Determine user who created this object from CRUD log """
if self.crud_event_create:
return self.crud_event_create.user
@property
def updated_by(self) -> Optional[models.Model]:
""" Determine user who last updated this object from CRUD log """
if self.crud_event_update:
return self.crud_event_update.user
extended_data = JSONField(default=dict, editable=False)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment