Hide keyboard shortcuts

Hot-keys on this page

r m x p   toggle line displays

j k   next/prev highlighted chunk

0   (zero) top of page

1   (one) first highlighted chunk

1# Imports 

2 

3from django.db import models 

4 

5# Exports 

6 

7__all__ = ( 

8 "AuditMixin", 

9) 

10 

11# Mixins 

12 

13 

14class AuditMixin(models.Model): 

15 """Base for other abstract auditing models. 

16 

17 The class serves two purposes: 

18 

19 1. Provide a centralized ``audit()`` method that child classes may call to save audit data. 

20 2. Act as a flag for the ``is_audit_model()`` function to indicate the presence of audit functionality. 

21 

22 """ 

23 

24 class Meta: 

25 abstract = True 

26 

27 def audit(self, user, commit=True): 

28 """Save the model along with audit data. 

29 

30 :param user: The user saving the record. 

31 :type user: AUTH_USER_MODEL 

32 

33 :param commit: Whether to save immediately. 

34 :type commit: bool 

35 

36 """ 

37 if commit: 

38 self.save()