python - Django email notification -
i want ask guidance on how django email notification https://docs.djangoproject.com/en/1.8/topics/email/#send-mail
i have basic task form , option assign someone, when form saved want send email notification assigned user.
job/task models.py
class job(models.model): completed = models.booleanfield(default=false) task_name = models.charfield(max_length=80, blank=false) description = models.charfield(max_length=80, blank=false) is_important = models.booleanfield(default=false) completion_date = models.datefield(blank=true, null=true) assign_to = models.foreignkey(user, blank=true, null=true) comments = models.textfield(blank=true) def __unicode__(self): return self.task_name
job/task view.py
@login_required def job(request): if request.method == 'post': form = jobform(request.post) if form.is_valid(): job_record = form.save(commit=false) job_record = form.save(commit=false) job_record.user = request.user job_record.save() return redirect('jobs:list') else: form = jobform() return render(request, 'jobs/form.html', {'form': form})
you there:
@login_required def job(request): form = jobform(request.post or none) if form.is_valid(): job_record = form.save(commit=false) job_record.assign_to = request.user job_record.save() send_mail( subject="subject", message="message", from_email="from@myserver.com", recipient_list=[job_record.assign_to.email] ) return redirect('jobs:list') return render(request, 'jobs/form.html', {'form': form})
Comments
Post a Comment