Django how to use post_save signals -
i had learn django signals but, don't known implement in project , how use in project. in project want send email alerts if matches particular criteria. in case need use post_save signals.i added code this. kindly share ideas.
models.py
class personal(models.model): user = models.onetoonefield(user) email = models.emailfield(max_length=100, blank=true, null=true) country = models.charfield(max_length=100, blank=true, null=true) state = models.charfield(max_length=100, blank=true, null=true) city = models.charfield(max_length=100, blank=true, null=true) class skills(models.model): user = models.foreignkey(user) skill = models.charfield(max_length=100, blank=true, null=true) class jobs(models.model): emp = models.foreignkey(user, unique=false) title = models.charfield(max_length=100) industry = models.charfield(max_length=100) functionalarea = models.charfield(max_length=100) min_exp = models.integerfield(default=0) max_exp = models.integerfield(default=0) city = models.charfield(max_length=100) state = models.charfield(max_length=100) country = models.charfield(max_length=100) empskills = models.charfield(max_length=100, blank=true, null=true)
here want match city , empskills of jobs table personal.city , skills.skill model. event occurs every job posting if matches 1 field send mail personal.email automatically. please give sample 1 , how use signal.
write function outside model handles when new job posted , finds people email.
you specify job
sender
post_save
signal , connect function.
from django.db.models.signals import post_save django.dispatch import receiver @receiver(post_save, sender=job) def handle_new_job(sender, **kwargs): job = kwargs.get('instance') logger.info("post_save : job : %s" % job) # find people email based on `job` instance
Comments
Post a Comment