def tree(self, request, pk=None): obj = self.get_object() qs = StructureUnit.objects.filter(structure=obj).select_related( 'type__structure_type', ).prefetch_related( 'identifiers', 'notes', 'structure__tagstructure_set', 'structure_unit_relations_a', ).annotate( tag_leaf_node=~Exists( TagVersion.objects.filter( tag__structures__structure=OuterRef('structure'), tag__structures__structure_unit=OuterRef('pk'), ).for_user(request.user), ) ) root_nodes = cache_tree_children(qs) dicts = [] context = self.get_serializer_context() for n in root_nodes: dicts.append(mptt_to_dict(n, StructureUnitSerializer, context=context)) return Response(dicts)
def list(self, request, *args, **kwargs): qs = self.filter_queryset(self.get_queryset()) root_nodes = cache_tree_children(qs) dicts = [] for n in root_nodes: dicts.append(mptt_to_dict(n, LocationSerializer)) return Response(dicts)
def tree(self, request, pk=None): obj = self.get_object() qs = StructureUnit.objects.filter(structure=obj) root_nodes = cache_tree_children(qs) dicts = [] for n in root_nodes: dicts.append(mptt_to_dict(n, StructureUnitSerializer)) return Response(dicts)