Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

145
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda