Add signal
This commit is contained in:
parent
eebd66fa27
commit
82d29d2795
|
|
@ -11,6 +11,9 @@ from easy_thumbnails.fields import ThumbnailerImageField
|
|||
from utils.methods import image_path, svg_image_path
|
||||
from utils.validators import svg_image_validator
|
||||
|
||||
from django.db.models.signals import pre_save
|
||||
from django.dispatch import receiver
|
||||
|
||||
|
||||
class ProjectBaseMixin(models.Model):
|
||||
"""Base mixin model."""
|
||||
|
|
@ -123,6 +126,23 @@ class BaseAttributes(ProjectBaseMixin):
|
|||
null=True, related_name='%(class)s_records_modified'
|
||||
)
|
||||
|
||||
@receiver(pre_save)
|
||||
def _pre_save(sender, instance, **kwargs):
|
||||
if not issubclass(sender, BaseAttributes):
|
||||
return
|
||||
|
||||
# debug
|
||||
from establishment.models import Employee
|
||||
if not isinstance(instance, Employee):
|
||||
return
|
||||
|
||||
user = False
|
||||
|
||||
instance.modified_by = user
|
||||
|
||||
if instance._state.adding:
|
||||
instance.created_by = user
|
||||
|
||||
class Meta:
|
||||
"""Meta class."""
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user