mirror of
https://github.com/wagtail/wagtail.git
synced 2024-12-01 11:41:20 +01:00
add ModelLogEntry model
This commit is contained in:
parent
74187b4fb4
commit
0bec76a6d7
37
wagtail/core/migrations/0063_modellogentry.py
Normal file
37
wagtail/core/migrations/0063_modellogentry.py
Normal file
@ -0,0 +1,37 @@
|
||||
# Generated by Django 3.1.12 on 2021-06-16 14:08
|
||||
|
||||
from django.conf import settings
|
||||
from django.db import migrations, models
|
||||
import django.db.models.deletion
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('contenttypes', '0002_remove_content_type_name'),
|
||||
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
|
||||
('wagtailcore', '0062_comment_models_and_pagesubscription'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.CreateModel(
|
||||
name='ModelLogEntry',
|
||||
fields=[
|
||||
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
|
||||
('label', models.TextField()),
|
||||
('action', models.CharField(blank=True, db_index=True, max_length=255)),
|
||||
('data_json', models.TextField(blank=True)),
|
||||
('timestamp', models.DateTimeField(verbose_name='timestamp (UTC)')),
|
||||
('content_changed', models.BooleanField(db_index=True, default=False)),
|
||||
('deleted', models.BooleanField(default=False)),
|
||||
('object_id', models.CharField(db_index=True, max_length=255)),
|
||||
('content_type', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='+', to='contenttypes.contenttype', verbose_name='content type')),
|
||||
('user', models.ForeignKey(blank=True, db_constraint=False, null=True, on_delete=django.db.models.deletion.DO_NOTHING, related_name='+', to=settings.AUTH_USER_MODEL)),
|
||||
],
|
||||
options={
|
||||
'verbose_name': 'model log entry',
|
||||
'verbose_name_plural': 'model log entries',
|
||||
'ordering': ['-timestamp', '-id'],
|
||||
},
|
||||
),
|
||||
]
|
@ -185,3 +185,28 @@ class BaseLogEntry(models.Model):
|
||||
return self.formatter.format_comment(self)
|
||||
else:
|
||||
return ''
|
||||
|
||||
|
||||
class ModelLogEntryManager(BaseLogEntryManager):
|
||||
def log_action(self, instance, action, **kwargs):
|
||||
kwargs.update(object_id=str(instance.pk))
|
||||
return super().log_action(instance, action, **kwargs)
|
||||
|
||||
|
||||
class ModelLogEntry(BaseLogEntry):
|
||||
"""
|
||||
Simple logger for generic Django models
|
||||
"""
|
||||
object_id = models.CharField(max_length=255, blank=False, db_index=True)
|
||||
|
||||
objects = ModelLogEntryManager()
|
||||
|
||||
class Meta:
|
||||
ordering = ['-timestamp', '-id']
|
||||
verbose_name = _('model log entry')
|
||||
verbose_name_plural = _('model log entries')
|
||||
|
||||
def __str__(self):
|
||||
return "ModelLogEntry %d: '%s' on '%s' with id %s" % (
|
||||
self.pk, self.action, self.object_verbose_name(), self.object_id
|
||||
)
|
||||
|
Loading…
Reference in New Issue
Block a user