Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

139
Visualizações
generic.Listview does not show in URL list in DRF Viewer

I'm missing something, but I don't know what it is. When I go to the DRF Viewer, alerts is not listed in the possible list of urls. all the other Rest URLs do.

here's my serializer.py:

class OptionSerializer(serializers.ModelSerializer):
    class Meta:
        model = Options
        fields = '__all__'

        validators = [
            UniqueTogetherValidator(
                queryset=Options.objects.all(),
                fields=('Member', 'skey', 'Time_Period')
            )
        ]

api.py:

class OptionViewSet(generics.ListCreateAPIView):
    serializer_class = OptionSerializer

    def get_queryset(self):
        """
        This view should return a list of all the options
        for the currently authenticated user.
        """
        user = self.request.user
        return Options.objects.filter(Member=user)

and my urls.py:

router = routers.DefaultRouter()
router.register(r'users', api.UserViewSet)
router.register(r'groups', api.GroupViewSet)
router.register(r'currency', api.BitCoinViewSet)
router.register(r'latest_prices', api.CurrencyLatestViewSet)
router.register(r'options', api.OptionViewSet.as_view, 'alerts')

urlpatterns = [
    url(r'^admin/', admin.site.urls),
    url(r'^api/', include(router.urls)),
    url(r'^api-auth/', include('rest_framework.urls', namespace='rest_framework'))

]

Why does the alert url not show up? Thanks.

about 4 years ago · Santiago Trujillo
1 Respostas
Responde à pergunta

0

Routers only work with ViewSets, but your OptionViewSet is an ordinary APIView.

You should be able to fix it by just using the appropriate mixins and base class:

class OptionViewSet(mixins.CreateModelMixin,
                    mixins.ListModelMixin,
                    viewsets.GenericViewSet):

    serializer_class = OptionSerializer

    def get_queryset(self):
        """
        This view should return a list of all the options
        for the currently authenticated user.
        """
        user = self.request.user
        return Options.objects.filter(Member=user)
about 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda