def get_children(self, obj): children = obj.children.all().annotate( length_2d_m=Length('geom'), start_point=Transform(StartPoint('geom'), settings.API_SRID), end_point=Transform(EndPoint('geom'), settings.API_SRID)) serializer_children = TrekListSerializer( children, many=True, context={'root_pk': obj.pk}) return serializer_children.data
def get_queryset(self, *args, **kwargs): queryset = trekking_models.Trek.objects.existing()\ .select_related('topo_object') \ .prefetch_related('topo_object__aggregations', 'attachments') \ .order_by('pk').annotate(length_2d_m=Length('geom')) if not self.action == 'list': queryset = queryset.annotate( geom2d_transformed=Transform(F('geom'), settings.API_SRID)) if 'portal' in self.request.GET: queryset = queryset.filter( Q(portal__name__in=self.request.GET['portal'].split(',')) | Q(portal=None)) return queryset.annotate(start_point=Transform(StartPoint('geom'), settings.API_SRID), end_point=Transform(EndPoint('geom'), settings.API_SRID)).\ filter(Q(published=True) | Q(trek_parents__parent__published=True, trek_parents__parent__deleted=False)).distinct()
def get_queryset(self, *args, **kwargs): lang = self.request.LANGUAGE_CODE queryset = trekking_models.Trek.objects.existing()\ .select_related('topo_object') \ .prefetch_related('topo_object__aggregations', 'attachments') \ .order_by('pk').annotate(length_2d_m=Length('geom')) if not self.action == 'list': queryset = queryset.annotate( geom2d_transformed=Transform(F('geom'), settings.API_SRID)) if self.action == 'list': queryset = queryset.annotate(count_parents=Count('trek_parents')).\ exclude(Q(count_parents__gt=0) & Q(published=False)) if 'portal' in self.request.GET: queryset = queryset.filter( Q(portal__name=self.request.GET['portal']) | Q(portal=None)) return queryset.annotate(start_point=Transform(StartPoint('geom'), settings.API_SRID), end_point=Transform(EndPoint('geom'), settings.API_SRID)). \ filter(Q(**{'published_{lang}'.format(lang=lang): True}) | Q(**{'trek_parents__parent__published_{lang}'.format(lang=lang): True, 'trek_parents__parent__deleted': False})).distinct()
def get_parents(self, obj): parents = obj.parents.all().annotate(length_2d_m=Length('geom'), start_point=Transform(StartPoint('geom'), settings.API_SRID), end_point=Transform(EndPoint('geom'), settings.API_SRID)) serializer_parents = TrekListSerializer(parents, many=True) return serializer_parents.data