parent
3d878cc7dc
commit
d39eb27b80
8 changed files with 66 additions and 5 deletions
@ -0,0 +1,20 @@ |
|||||||
|
# -*- coding: utf-8 -*- |
||||||
|
# Generated by Django 1.11.6 on 2017-10-24 13:52 |
||||||
|
from __future__ import unicode_literals |
||||||
|
|
||||||
|
from django.db import migrations, models |
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration): |
||||||
|
|
||||||
|
dependencies = [ |
||||||
|
('journals', '0004_auto_20171023_1234'), |
||||||
|
] |
||||||
|
|
||||||
|
operations = [ |
||||||
|
migrations.AlterField( |
||||||
|
model_name='journal', |
||||||
|
name='action_type', |
||||||
|
field=models.SmallIntegerField(choices=[(0, 'try'), (1, 'yes'), (2, 'no'), (3, 'favorite'), (4, 'watch'), (5, 'start'), (6, 'end'), (7, 'create'), (8, 'update'), (9, 'delete')]), |
||||||
|
), |
||||||
|
] |
||||||
@ -0,0 +1,20 @@ |
|||||||
|
from rest_framework import serializers |
||||||
|
from library.models import Article |
||||||
|
|
||||||
|
|
||||||
|
class ArticleSerializer(serializers.ModelSerializer): |
||||||
|
tags = serializers.SerializerMethodField() |
||||||
|
section = serializers.SerializerMethodField() |
||||||
|
|
||||||
|
class Meta: |
||||||
|
model = Article |
||||||
|
exclude = ('css', 'js', 'page', 'head_title', 'public', |
||||||
|
'head_description', 'head_image', 'id') |
||||||
|
|
||||||
|
@staticmethod |
||||||
|
def get_tags(self): |
||||||
|
return [i.name for i in self.tags.all()] |
||||||
|
|
||||||
|
@staticmethod |
||||||
|
def get_section(self): |
||||||
|
return self.section.name if self.section else 'undefined' |
||||||
@ -0,0 +1,6 @@ |
|||||||
|
from django.conf.urls import url |
||||||
|
from library import views |
||||||
|
|
||||||
|
urlpatterns = [ |
||||||
|
url(r'$', views.LibraryListView.as_view()), |
||||||
|
] |
||||||
@ -0,0 +1,14 @@ |
|||||||
|
from rest_framework.renderers import JSONRenderer |
||||||
|
from rest_framework.response import Response |
||||||
|
from rest_framework.views import APIView |
||||||
|
|
||||||
|
from library.models import Article |
||||||
|
from library.serializers import ArticleSerializer |
||||||
|
|
||||||
|
|
||||||
|
class LibraryListView(APIView): |
||||||
|
renderer_classes = (JSONRenderer,) |
||||||
|
status_code = 200 |
||||||
|
|
||||||
|
def get(self, request): |
||||||
|
return Response([ArticleSerializer(i).data for i in Article.objects.filter(public=True)], self.status_code) |
||||||
Loading…
Reference in new issue