Monday, March 30, 2020

Re: Having issue sending email when model is save and not updated.

Hi,

Use Django signals presave and postsave.


Regards,
Sunil H N
-sent from MacBook Air











On 31-Mar-2020, at 01:48, Isaac Imafidon <isaac.imafidon69@gmail.com> wrote:

Am working on an ecommerce project and i want to be able to do two things before the model save .
1) I want to update the cost of an item
2) I want to send two  email to the receiver . One when the object just gets created while the other when the object gets updated.
I go through django documentation about pre_save signal and post_save signal but don't really understand it.

This is my model
 
class Item(models.Model):
    # set of possible order statuses
    ITEM_STATUSES = (('PICK UP','PICK UP'), #default
        ('IN TRANSIT','IN TRANSIT'), # To let ur customer know their order is now been process
        ('DELIVERED','DELIVERED'),#Now delivered to them

        )
    cost = models.DecimalField(max_digits=10, decimal_places=2)
    sender_name = models.CharField(max_length=150)
    sender_email = models.EmailField()
    receiver_name = models.CharField(max_length=150)
    receiver_email = models.EmailField()

Before this model is save i want to update the cost by adding 10% of the cost variable to create a new cost that will be shown in the view also i want to send email to receiver_email  variable. Once the user update the model i want to still add my 10% to the cost and instead of sending email one, i will send email two.
Something like this

....Model as before
if just_created :
   update the cost by 10% before save to the database
   send email 1 carrying the new cost variable and the receiver name to receiver email
   then save()
else:
   update the cost by 10% before saving to the database
   send email 2 carrying the new cost variable and the receiver name to receiver email
   then save()

Please guys i really need your help in this.

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/a9ed1900-b432-49f2-8899-4a96a02eef66%40googlegroups.com.

No comments:

Post a Comment