我用django-audit-log,我很滿意。
Django審計日誌可以跟蹤多個模型,每個模型都在它自己的附加表中。所有這些表格都非常統一,因此創建一個顯示所有模型數據的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管理展示,您可以創建一個unmanaged model(但這絕不裝置需要):
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的審計日誌創建的,這僅僅是創建用於從它顯示數據的模型。 這可能是在一些粗魯的防篡改保護拋出一個好主意:
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_
場和一個額外的「action_model」字段可能包含VARCHAR一個SQL視圖引用模型本身(可能只是原始表名)。
我想知道我們cud在'PostgreSQL'中寫了'Triggers',當一個新行插入到Article,Media,Comments表等等時,它會填充Log表。這是個好主意? – 2012-03-30 15:07:22
取決於。如果將來您有一種情況,用戶可以上傳包含媒體的文章(可能,對嗎?),並且這是在單個Web服務調用中處理的? – ArjunShankar 2012-03-30 15:13:13
真.. .. ..我會看到它.. !! ..實際上服務都是完整的.. !! ..我thot可能是我沒有把一個額外的代碼..通常thanx ..! ! – 2012-03-30 15:40:07