Add historical records to every model for auditing
This commit is contained in:
parent
30294e7332
commit
bad18e069a
|
@ -1,10 +1,11 @@
|
|||
from django.apps import apps
|
||||
from django.contrib import admin
|
||||
from django.contrib.admin.sites import AlreadyRegistered
|
||||
from simple_history.admin import SimpleHistoryAdmin
|
||||
|
||||
app_models = apps.get_app_config('api').get_models()
|
||||
for model in app_models:
|
||||
try:
|
||||
admin.site.register(model)
|
||||
admin.site.register(model, SimpleHistoryAdmin)
|
||||
except AlreadyRegistered:
|
||||
pass
|
||||
|
|
|
@ -2,6 +2,10 @@ from datetime import date, datetime
|
|||
from django.db import models
|
||||
from django.contrib.auth.models import User
|
||||
from django.utils.timezone import now
|
||||
from simple_history.models import HistoricalRecords
|
||||
from simple_history import register
|
||||
|
||||
register(User)
|
||||
|
||||
IGNORE = '+'
|
||||
|
||||
|
@ -38,6 +42,8 @@ class Member(models.Model):
|
|||
paused_date = models.DateField(blank=True, null=True)
|
||||
monthly_fees = models.IntegerField(default=55, blank=True, null=True)
|
||||
|
||||
history = HistoricalRecords()
|
||||
|
||||
class Transaction(models.Model):
|
||||
user = models.ForeignKey(User, related_name='transactions', blank=True, null=True, on_delete=models.SET_NULL)
|
||||
recorder = models.ForeignKey(User, related_name=IGNORE, blank=True, null=True, on_delete=models.SET_NULL)
|
||||
|
@ -58,15 +64,21 @@ class Transaction(models.Model):
|
|||
report_type = models.TextField(blank=True, null=True)
|
||||
report_memo = models.TextField(blank=True, null=True)
|
||||
|
||||
history = HistoricalRecords()
|
||||
|
||||
class PayPalHint(models.Model):
|
||||
account = models.CharField(unique=True, max_length=13)
|
||||
member_id = models.IntegerField()
|
||||
|
||||
history = HistoricalRecords()
|
||||
|
||||
class IPN(models.Model):
|
||||
datetime = models.DateTimeField(auto_now_add=True)
|
||||
data = models.TextField()
|
||||
status = models.CharField(max_length=32)
|
||||
|
||||
history = HistoricalRecords()
|
||||
|
||||
class Card(models.Model):
|
||||
user = models.ForeignKey(User, related_name='cards', blank=True, null=True, on_delete=models.SET_NULL)
|
||||
|
||||
|
@ -76,11 +88,15 @@ class Card(models.Model):
|
|||
last_seen_at = models.DateField(default=date.today, blank=True, null=True)
|
||||
active_status = models.CharField(max_length=32, blank=True, null=True)
|
||||
|
||||
history = HistoricalRecords()
|
||||
|
||||
class Course(models.Model):
|
||||
name = models.TextField(blank=True, null=True)
|
||||
description = models.TextField(blank=True, null=True)
|
||||
is_old = models.BooleanField(default=False)
|
||||
|
||||
history = HistoricalRecords()
|
||||
|
||||
class Session(models.Model):
|
||||
instructor = models.ForeignKey(User, related_name='teaching', blank=True, null=True, on_delete=models.SET_NULL)
|
||||
course = models.ForeignKey(Course, related_name='sessions', blank=True, null=True, on_delete=models.SET_NULL)
|
||||
|
@ -91,6 +107,8 @@ class Session(models.Model):
|
|||
cost = models.DecimalField(max_digits=5, decimal_places=2)
|
||||
max_students = models.IntegerField(blank=True, null=True)
|
||||
|
||||
history = HistoricalRecords()
|
||||
|
||||
class Training(models.Model):
|
||||
user = models.ForeignKey(User, related_name='training', blank=True, null=True, on_delete=models.SET_NULL)
|
||||
session = models.ForeignKey(Session, related_name='students', blank=True, null=True, on_delete=models.SET_NULL)
|
||||
|
@ -99,3 +117,5 @@ class Training(models.Model):
|
|||
attendance_status = models.TextField(blank=True, null=True)
|
||||
sign_up_date = models.DateField(default=date.today, blank=True, null=True)
|
||||
paid_date = models.DateField(blank=True, null=True)
|
||||
|
||||
history = HistoricalRecords()
|
||||
|
|
|
@ -66,6 +66,7 @@ INSTALLED_APPS = [
|
|||
'allauth.account',
|
||||
'allauth.socialaccount', # to support user deletion
|
||||
'rest_auth.registration',
|
||||
'simple_history',
|
||||
]
|
||||
|
||||
MIDDLEWARE = [
|
||||
|
@ -76,6 +77,7 @@ MIDDLEWARE = [
|
|||
'django.contrib.auth.middleware.AuthenticationMiddleware',
|
||||
'django.contrib.messages.middleware.MessageMiddleware',
|
||||
'django.middleware.clickjacking.XFrameOptionsMiddleware',
|
||||
'simple_history.middleware.HistoryRequestMiddleware',
|
||||
]
|
||||
|
||||
ROOT_URLCONF = 'apiserver.urls'
|
||||
|
|
|
@ -10,6 +10,7 @@ defusedxml==0.6.0
|
|||
Django==3.0.2
|
||||
django-allauth==0.41.0
|
||||
django-rest-auth==0.9.5
|
||||
django-simple-history==2.8.0
|
||||
djangorestframework==3.11.0
|
||||
docutils==0.16
|
||||
fuzzywuzzy==0.17.0
|
||||
|
|
Loading…
Reference in New Issue
Block a user