def remove_widgets(dashboard_widgets, widget_data):
    """
    Removes current widgets belonging to dashboard not in widget_data.
    Returns remaining widgets.
    """
    widget_ids = [wd['id'] for wd in widget_data]
    dashboard_widgets.exclude(
        id__in=widget_ids
    ).delete()
    return dashboard_widgets.filter(
        id__in=widget_ids
    )