from django.db.models import Model
from django.utils.translation import ugettext_lazy as _
from audit_log.models.fields import CreatingUserField, CreatingSessionKeyField, LastUserField, LastSessionKeyField

class AuthStampedModel(Model):
	"""
	An abstract base class model that provides auth and session information
	fields.
	"""
	created_by = CreatingUserField(verbose_name = _("created by"), related_name = "created_%(app_label)s_%(class)s_set")
	created_with_session_key = CreatingSessionKeyField(_("created with session key"))
	modified_by =  LastUserField(verbose_name = _("modified by"), related_name = "modified_%(app_label)s_%(class)s_set")
	modified_with_session_key = LastSessionKeyField(_("modified with session key"))

	class Meta:
		abstract = True

from django.db.models import Model, SET_NULL
from django.utils.translation import ugettext_lazy as _
from audit_log.models.fields import CreatingUserField, CreatingSessionKeyField, LastUserField, LastSessionKeyField

class AuthStampedModel(Model):
	"""
	An abstract base class model that provides auth and session information
	fields.
	"""
	created_by = CreatingUserField(on_delete=SET_NULL, null=True, verbose_name = _("created by"), related_name = "created_%(app_label)s_%(class)s_set")
	created_with_session_key = CreatingSessionKeyField(_("created with session key"))
	modified_by =  LastUserField(on_delete=SET_NULL, null=True, verbose_name = _("modified by"), related_name = "modified_%(app_label)s_%(class)s_set")
	modified_with_session_key = LastSessionKeyField(_("modified with session key"))

	class Meta:
		abstract = True

Add mandatory `on_delete` and allow nulls
Add mandatory `on_delete` and allow nulls

I assume it's better to allow nulls than to have auth stamped models
disappear with deleted users.

- from django.db.models import Model
+ from django.db.models import Model, SET_NULL
  from django.utils.translation import ugettext_lazy as _
  from audit_log.models.fields import CreatingUserField, CreatingSessionKeyField, LastUserField, LastSessionKeyField
  
  class AuthStampedModel(Model):
  	"""
  	An abstract base class model that provides auth and session information
  	fields.
  	"""
- 	created_by = CreatingUserField(verbose_name = _("created by"), related_name = "created_%(app_label)s_%(class)s_set")
+ 	created_by = CreatingUserField(on_delete=SET_NULL, null=True, verbose_name = _("created by"), related_name = "created_%(app_label)s_%(class)s_set")
  	created_with_session_key = CreatingSessionKeyField(_("created with session key"))
- 	modified_by =  LastUserField(verbose_name = _("modified by"), related_name = "modified_%(app_label)s_%(class)s_set")
+ 	modified_by =  LastUserField(on_delete=SET_NULL, null=True, verbose_name = _("modified by"), related_name = "modified_%(app_label)s_%(class)s_set")
  	modified_with_session_key = LastSessionKeyField(_("modified with session key"))
  
  	class Meta:
  		abstract = True
  
Add mandatory `on_delete` and allow nulls
## Code Before:
from django.db.models import Model
from django.utils.translation import ugettext_lazy as _
from audit_log.models.fields import CreatingUserField, CreatingSessionKeyField, LastUserField, LastSessionKeyField

class AuthStampedModel(Model):
	"""
	An abstract base class model that provides auth and session information
	fields.
	"""
	created_by = CreatingUserField(verbose_name = _("created by"), related_name = "created_%(app_label)s_%(class)s_set")
	created_with_session_key = CreatingSessionKeyField(_("created with session key"))
	modified_by =  LastUserField(verbose_name = _("modified by"), related_name = "modified_%(app_label)s_%(class)s_set")
	modified_with_session_key = LastSessionKeyField(_("modified with session key"))

	class Meta:
		abstract = True

## Instruction:
Add mandatory `on_delete` and allow nulls
## Code After:
from django.db.models import Model, SET_NULL
from django.utils.translation import ugettext_lazy as _
from audit_log.models.fields import CreatingUserField, CreatingSessionKeyField, LastUserField, LastSessionKeyField

class AuthStampedModel(Model):
	"""
	An abstract base class model that provides auth and session information
	fields.
	"""
	created_by = CreatingUserField(on_delete=SET_NULL, null=True, verbose_name = _("created by"), related_name = "created_%(app_label)s_%(class)s_set")
	created_with_session_key = CreatingSessionKeyField(_("created with session key"))
	modified_by =  LastUserField(on_delete=SET_NULL, null=True, verbose_name = _("modified by"), related_name = "modified_%(app_label)s_%(class)s_set")
	modified_with_session_key = LastSessionKeyField(_("modified with session key"))

	class Meta:
		abstract = True
