Reputation: 863
In my app, whenever a question is deleted, it shows a django message that question is deleted. Related code is:
from django.contrib import messages
msg= _('Question is deleted')
messages.info(request, msg)
The message gets displayed as desired, however I want Display message to last longer say for minimum 10 sec. or till the user clicks on it.
In django docs saw expiration of messages but still could not figure out, and I have nothing like message storage which i can set to false.
Help appreciated :)
Upvotes: 3
Views: 6418
Reputation: 2086
The thing you want to do is javascript domain. Below code will display your messages for 10 sec or you can close it manually. In template you can do like this:
{% for message in messages %}
<div class="message">
{{ message }}
<a href="#" class="del-msg">×</a>
</div>
{% endfor %}
And in javascript:
<script>
$(document).ready(function() {
// messages timeout for 10 sec
setTimeout(function() {
$('.message').fadeOut('slow');
}, 10000); // <-- time in milliseconds, 1000 = 1 sec
// delete message
$('.del-msg').live('click',function(){
$('.del-msg').parent().attr('style', 'display:none;');
})
});
</script>
Upvotes: 13