def seconds(duration):
    """
    Return the "seconds" portion of a duration.
    :param duration: a timedelta instance.
    :returns: an integer representing the number of seconds in duration.
    """
    if not duration:
        return 0
    try:
        h, m, s = utils.duration_parts(duration)
        return s
    except (ValueError, TypeError):
        return 0

    Return the "seconds" portion of a duration.
    :param duration: a timedelta instance.
    :returns: an integer representing the number of seconds in duration.
    
core/templatetags/duration.py