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.
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)