May 2018
Beginner to intermediate
526 pages
11h 57m
English
Sometimes, your users might perform an action multiple times. They might click several times on the LIKE or UNLIKE buttons or perform the same action multiple times in a short period of time. This will easily lead to storing and displaying duplicate actions. To avoid this, we will improve the create_action() function to skip obvious duplicated actions.
Edit the utils.py file of the actions application, as follows:
import datetimefrom django.utils import timezonefrom django.contrib.contenttypes.models import ContentTypefrom .models import Actiondef create_action(user, verb, target=None): # check for any similar action made in the last minute now = timezone.now() last_minute = now - datetime.timedelta(seconds=60) ...
Read now
Unlock full access