def get_watched_content_for_user(user): """Returns a dict where: - The key is the content_type model - The values are list of id's of the different objects watched by the user """ if user.is_anonymous(): return {} user_watches = {} for (ct_model, object_id) in user.watched.values_list("content_type__model", "object_id"): list = user_watches.get(ct_model, []) list.append(object_id) user_watches[ct_model] = list #Now for projects, projects_watched = get_projects_watched(user) project_content_type_model=ContentType.objects.get(app_label="projects", model="project").model user_watches[project_content_type_model] = projects_watched.values_list("id", flat=True) return user_watches