Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

138
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!