models.py: Add post_save to Message.

Flushes message from cache after a message.save(). Needed for tests
where we directly manipulate Message objects in the database.
This commit is contained in:
Rishi Gupta 2016-07-07 17:25:55 -07:00 committed by Tim Abbott
parent f1ba3ded42
commit 07e7230ae1

View File

@ -1141,6 +1141,13 @@ def get_context_for_message(message):
pub_date__gt=message.pub_date - timedelta(minutes=15),
).order_by('-id')[:10]
def flush_message(sender, **kwargs):
# type: (Any, **Any) -> None
message = kwargs['instance']
cache_delete(to_dict_cache_key(message, False))
cache_delete(to_dict_cache_key(message, True))
post_save.connect(flush_message, sender=Message)
# Whenever a message is sent, for each user current subscribed to the
# corresponding Recipient object, we add a row to the UserMessage