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.