Commit cbf7a2b1 authored by luxcem's avatar luxcem
Browse files

adds api for articles

parent c070ee3a
from rest_framework import routers
class DefaultRouter(routers.DefaultRouter):
Extends `DefaultRouter` class to add a method for extending url
routes from another router. # from
def extend(self, router):
Extend the routes with url routes of the passed in router.
router: SimpleRouter instance containing route definitions.
from rest_framework import serializers
from rp.models import Article
class ArticleSerializer(serializers.ModelSerializer):
class Meta:
model = Article
fields = "__all__"
from rest_framework import routers
from .views import ArticleViewSet
router = routers.DefaultRouter()
router.register(r"articles", ArticleViewSet)
from rest_framework import viewsets
from rp.models import Article
from .serializers import ArticleSerializer
class ArticleViewSet(viewsets.ModelViewSet):
queryset = Article.objects.all()
serializer_class = ArticleSerializer
......@@ -5,7 +5,15 @@ rp_new URL Configuration
from django.conf.urls import url, include
from django.contrib import admin
# Django rest framework router
from core.routers import DefaultRouter
from rp.api.urls import router as rp_router
router = DefaultRouter()
urlpatterns = [
url(r"^api/", include(router.urls, namespace="api")),
url(r"^rp/", include("rp.urls"))
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment