This question is connected to this one: Django - disable model editing
This is my code:
def save(self, *args, **kwargs):
if self.pk is None:
print "THIS IS ADD ACTION. NOT DELETE OR CHANGE !!!"
numberOfAvalableBooks = Book.objects.get(id=self.book.id).amount
print 'numberOfAvalableBooks %s' % numberOfAvalableBooks
if self.get_action_display() == 'Out':
if numberOfAvalableBooks - self.amount < 0:
return "YOU DO NOT HAVE ENOUGH BOOKS !!!"
super(Transaction, self).save(*args, **kwargs)
# UPDATE AMOUNT
book = Book.objects.get(id=self.book.id)
if self.get_action_display() == 'Out':
book.amount -= self.amount
elif self.get_action_display() == 'In':
book.amount += self.amount
else:
print "UNKNOWN ACTION !!!"
book.save()
else:
print self.pk
return "CHANGE ACTION DISABLED !!!"
This is working fine, no update or delete is possible.
What I do not like is that after clicking "Save" button I still have yellow message with "The ….. was added successfully.".
Is it possible and how, to replace that message, and make it with different color ?
Thanks