(domains, start_date=None, end_date=None)
return (NavigationEventAudit.objects
            .values("user", "domain", "session_key")  # GROUP BY fields
            .annotate(access_time=Min("event_date"))
            .values("user", "domain", "access_time")  # SELECT fields
            .filter(**where)
            .order_by("access_time")
            .iterator())
Query NavigationEventAudit events for _first event matching any of
    `domains` within each authenticated session_.

    NOTE: This function does _not_ query couch.

    NOTE: This function may return multiple "access events" from the same
          session (if multiple `domains` were accessed in the same session).

    Resulting SQL query:

    ```sql
    SELECT
        "user",
        domain,
        MIN(event_date) AS access_time
    FROM auditcare_navigationeventaudit
    WHERE (
        domain IN ( {domains} )
        AND event_date > {start_date}
        AND event_date <= {end_date}
        AND "user" IS NOT NULL
        AND session_key IS NOT NULL
    )
    GROUP BY ("user", domain, session_key)
    ORDER BY access_time ASC;
    ```
Query NavigationEventAudit events for _first event matching any of
    `domains` within each authenticated session_.
Query NavigationEventAudit events for _first event matching any of domains within each authenticated session_ .
def get_domain_first_access_times(domains, start_date=None, end_date=None):
    """Query NavigationEventAudit events for _first event matching any of
    `domains` within each authenticated session_.

    NOTE: This function does _not_ query couch.

    NOTE: This function may return multiple "access events" from the same
          session (if multiple `domains` were accessed in the same session).

    Resulting SQL query:

    ```sql
    SELECT
        "user",
        domain,
        MIN(event_date) AS access_time
    FROM auditcare_navigationeventaudit
    WHERE (
        domain IN ( {domains} )
        AND event_date > {start_date}
        AND event_date <= {end_date}
        AND "user" IS NOT NULL
        AND session_key IS NOT NULL
    )
    GROUP BY ("user", domain, session_key)
    ORDER BY access_time ASC;
    ```
    """
    sql_start_date = determine_sql_start_date(start_date)
    where = get_date_range_where(sql_start_date, end_date)
    where["domain__in"] = domains
    where["user__isnull"] = False
    where["session_key__isnull"] = False
    return (NavigationEventAudit.objects
            .values("user", "domain", "session_key")  # GROUP BY fields
            .annotate(access_time=Min("event_date"))
            .values("user", "domain", "access_time")  # SELECT fields
            .filter(**where)
            .order_by("access_time")
            .iterator())
def get_domain_first_access_times ( domains , start_date = None , end_date = None ) : sql_start_date = determine_sql_start_date ( start_date ) where = get_date_range_where ( sql_start_date , end_date ) where [ "domain__in" ] = domains where [ "user__isnull" ] = False where [ "session_key__isnull" ] = False return ( NavigationEventAudit . objects . values ( "user" , "domain" , "session_key" ) # GROUP BY fields . annotate ( access_time = Min ( "event_date" ) ) . values ( "user" , "domain" , "access_time" ) # SELECT fields . filter ( * * where ) . order_by ( "access_time" ) . iterator ( ) )