mirror of
https://github.com/fspc/workstand.git
synced 2025-02-23 09:13:23 -05:00
Add basic DRF endpoint.
This commit is contained in:
parent
2665d5e4da
commit
04376ff35e
8
bikeshop_project/bike/serializers.py
Normal file
8
bikeshop_project/bike/serializers.py
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
from rest_framework import serializers
|
||||||
|
|
||||||
|
from bike.models import Bike
|
||||||
|
|
||||||
|
|
||||||
|
class BikeSerializer(serializers.HyperlinkedModelSerializer):
|
||||||
|
class Meta:
|
||||||
|
model = Bike
|
@ -1,7 +1,13 @@
|
|||||||
from django.conf.urls import url
|
from django.conf.urls import url, include
|
||||||
|
from rest_framework import routers
|
||||||
|
|
||||||
|
from bike import views
|
||||||
from .views import BikesView
|
from .views import BikesView
|
||||||
|
|
||||||
|
router = routers.DefaultRouter()
|
||||||
|
router.register(r'bikes', views.BikeViewSet)
|
||||||
|
|
||||||
urlpatterns = [
|
urlpatterns = [
|
||||||
|
url(r'^api/', include(router.urls, namespace='api')),
|
||||||
url(r'^$', BikesView.as_view(), name='bikes')
|
url(r'^$', BikesView.as_view(), name='bikes')
|
||||||
]
|
]
|
||||||
|
@ -1,6 +1,10 @@
|
|||||||
from django.contrib.auth.decorators import login_required
|
from django.contrib.auth.decorators import login_required
|
||||||
from django.utils.decorators import method_decorator
|
from django.utils.decorators import method_decorator
|
||||||
from django.views.generic import TemplateView
|
from django.views.generic import TemplateView
|
||||||
|
from rest_framework import viewsets
|
||||||
|
|
||||||
|
from bike.models import Bike
|
||||||
|
from bike.serializers import BikeSerializer
|
||||||
|
|
||||||
|
|
||||||
@method_decorator(login_required, name='dispatch')
|
@method_decorator(login_required, name='dispatch')
|
||||||
@ -9,3 +13,8 @@ class BikesView(TemplateView):
|
|||||||
|
|
||||||
def get(self, request):
|
def get(self, request):
|
||||||
return self.render_to_response({})
|
return self.render_to_response({})
|
||||||
|
|
||||||
|
|
||||||
|
class BikeViewSet(viewsets.ModelViewSet):
|
||||||
|
queryset = Bike.objects.all()
|
||||||
|
serializer_class = BikeSerializer
|
||||||
|
@ -161,3 +161,11 @@ HAYSTACK_SIGNAL_PROCESSOR = 'haystack.signals.RealtimeSignalProcessor'
|
|||||||
|
|
||||||
LOGIN_REDIRECT_URL = 'home'
|
LOGIN_REDIRECT_URL = 'home'
|
||||||
LOGIN_URL = 'login'
|
LOGIN_URL = 'login'
|
||||||
|
|
||||||
|
REST_FRAMEWORK = {
|
||||||
|
# Use Django's standard `django.contrib.auth` permissions,
|
||||||
|
# or allow read-only access for unauthenticated users.
|
||||||
|
'DEFAULT_PERMISSION_CLASSES': [
|
||||||
|
'rest_framework.permissions.DjangoModelPermissionsOrAnonReadOnly'
|
||||||
|
]
|
||||||
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user