django-audit-logを使用しましたが、非常に満足しています。
Django-audit-log は、それぞれ独自の追加テーブルで複数のモデルを追跡できます。これらのテーブルはすべてかなり統一されているため、すべてのモデルのデータを表示する SQL ビューを作成するのはかなり簡単です。
単一のモデル (「Pauza」) を追跡するために行ったことは次のとおりです。
class Pauza(models.Model):
started = models.TimeField(null=True, blank=False)
ended = models.TimeField(null=True, blank=True)
#... more fields ...
audit_log = AuditLog()
変更を Django Admin に表示したい場合は、管理されていないモデルを作成できます(ただし、これは必須ではありません)。
class PauzaAction(models.Model):
started = models.TimeField(null=True, blank=True)
ended = models.TimeField(null=True, blank=True)
#... more fields ...
# fields added by Audit Trail:
action_id = models.PositiveIntegerField(primary_key=True, default=1, blank=True)
action_user = models.ForeignKey(User, null=True, blank=True)
action_date = models.DateTimeField(null=True, blank=True)
action_type = models.CharField(max_length=31, choices=(('I', 'create'), ('U', 'update'), ('D', 'delete'),), null=True, blank=True)
pauza = models.ForeignKey(Pauza, db_column='id', on_delete=models.DO_NOTHING, default=0, null=True, blank=True)
class Meta:
db_table = 'testapp_pauzaauditlogentry'
managed = False
app_label = 'testapp'
テーブルtestapp_pauzaauditlogentry
は django-audit-log によって自動的に作成されます。これは、そこからデータを表示するためのモデルを作成するだけです。無作法な改ざん防止策を導入することをお勧めします。
class PauzaAction(models.Model):
# ... all like above, plus:
def save(self, *args, **kwargs):
raise Exception('Permission Denied')
def delete(self, *args, **kwargs):
raise Exception('Permission Denied')
action_
先ほど言ったように、4 つのフィールドと、モデル自体への varchar 参照 (おそらく元のテーブル名) を含むことができる追加の「action_model」フィールドを持つ SQL ビューを作成できると思います。