Commit f2479511 authored by Luis García's avatar Luis García
Browse files

Update blog api and remove comment model

parent 681a307c
"""
from .models import Comment
from django.forms import ModelForm
class CommentForm(ModelForm):
class Meta:
model = Comment
fields = ['content', 'post']
\ No newline at end of file
fields = ['content', 'post']
"""
\ No newline at end of file
......@@ -24,8 +24,9 @@ class Post(models.Model):
first_paragraph = models.TextField(verbose_name="First paragraph")
content = RichTextUploadingField(verbose_name='Content')
image = models.ImageField(verbose_name="Image", upload_to='posts/%Y-%m/')
pin_up = models.BooleanField(verbose_name="Pin up", default=False)
enable_comments = models.BooleanField(verbose_name="Enable comments", default=True)
rating = models.PositiveIntegerField(verbose_name='Rating', default=0)
#pin_up = models.BooleanField(verbose_name="Pin up", default=False)
#enable_comments = models.BooleanField(verbose_name="Enable comments", default=True)
#order = models.IntegerField(verbose_name="Order", default=1)
owner = models.ForeignKey(User, verbose_name='Owner', on_delete=models.CASCADE, related_name='posts')
category = models.ForeignKey(Category, verbose_name='Category', on_delete=models.CASCADE, related_name='posts')
......@@ -41,6 +42,7 @@ class Post(models.Model):
def __str__(self):
return self.title
"""
# Model for Post comment
class Comment(models.Model):
content = models.TextField(verbose_name="Content")
......@@ -69,6 +71,7 @@ class Reply(models.Model):
def __str__(self):
return self.content
"""
# Model for Tag
class Tag(models.Model):
......
from rest_framework.serializers import ModelSerializer
from api.utils import AsymetricRelatedField
from core.serializers import UserSerializer
from .models import Post, Comment, Reply, Category, Tag, PostTag
#from .models import Post, Comment, Reply, Category, Tag, PostTag
from .models import Post, Category, Tag, PostTag
class CategorySerializer(ModelSerializer):
class Meta:
model = Category
fields = ('id', 'name', 'description')
ref_name = 'Blog Category'
class PostSerializer(ModelSerializer):
category = AsymetricRelatedField.from_serializer(CategorySerializer)()
......@@ -15,8 +17,9 @@ class PostSerializer(ModelSerializer):
class Meta:
model = Post
fields = ('id', 'slug', 'title', 'first_paragraph', 'content', 'image', 'pin_up', 'enable_comments', 'owner', 'category', 'created')
fields = ('id', 'slug', 'title', 'first_paragraph', 'content', 'image', 'rating', 'owner', 'category', 'created')
"""
class CommentSerializer(ModelSerializer):
class Meta:
......@@ -28,6 +31,7 @@ class ReplySerializer(ModelSerializer):
class Meta:
model = Reply
fields = ('id', 'content', 'username', 'email', 'Comment', 'created')
"""
class TagSerializer(ModelSerializer):
......
......@@ -3,7 +3,8 @@ from rest_framework.routers import DefaultRouter
#Blog views
from .views import PostListView, PostCreateView, PostDetailView, PostUpdateView
#Api blog views
from .views import PostViewSet, CommentViewSet, ReplyViewSet, CategoryViewSet, TagViewSet, PostTagViewSet
#from .views import PostViewSet, CommentViewSet, ReplyViewSet, CategoryViewSet, TagViewSet, PostTagViewSet
from .views import PostViewSet, CategoryViewSet, TagViewSet, PostTagViewSet
blog_patterns = ([
#Views for blog
......@@ -16,8 +17,8 @@ blog_patterns = ([
#views for blog api
router = DefaultRouter()
router.register(r'posts', PostViewSet, basename='posts')
router.register(r'comments', CommentViewSet, basename='comments')
router.register(r'replies', ReplyViewSet, basename='replies')
#router.register(r'comments', CommentViewSet, basename='comments')
#router.register(r'replies', ReplyViewSet, basename='replies')
router.register(r'categories', CategoryViewSet, basename='categories')
router.register(r'tags', TagViewSet, basename='tags')
router.register(r'post-tags', PostTagViewSet, basename='ost-tags')
......
from .aplication import PostListView, PostCreateView, PostDetailView, PostUpdateView
from .api import PostViewSet, CommentViewSet, ReplyViewSet, CategoryViewSet, TagViewSet, PostTagViewSet
\ No newline at end of file
#from .api import PostViewSet, CommentViewSet, ReplyViewSet, CategoryViewSet, TagViewSet, PostTagViewSet
from .api import PostViewSet, CategoryViewSet, TagViewSet, PostTagViewSet
\ No newline at end of file
......@@ -3,8 +3,10 @@ from rest_framework.viewsets import ModelViewSet
from rest_framework.permissions import IsAuthenticated
from rest_framework_extensions.mixins import NestedViewSetMixin
from api.permissions import IsSuperOrReadOnly, IsAuthOrReadOnly, IsStaffOrReadOnly
from blog.models import Post, Comment, Reply, Category, Tag, PostTag
from blog.serializers import PostSerializer, CommentSerializer, ReplySerializer, CategorySerializer, TagSerializer, PostTagSerializer
#from blog.models import Post, Comment, Reply, Category, Tag, PostTag
from blog.models import Post, Category, Tag, PostTag
#from blog.serializers import PostSerializer, CommentSerializer, ReplySerializer, CategorySerializer, TagSerializer, PostTagSerializer
from blog.serializers import PostSerializer, CategorySerializer, TagSerializer, PostTagSerializer
############################################################
#REST API for Post
......@@ -18,7 +20,7 @@ class PostViewSet(NestedViewSetMixin, ModelViewSet):
filter_backends = (DjangoFilterBackend,)
filterset_fields = ('slug','category','tags__tag')
"""
############################################################
#REST API for Comment
############################################################
......@@ -57,7 +59,7 @@ class ReplyViewSet(NestedViewSetMixin, ModelViewSet):
request.data['username'] = user.username
request.data['email'] = user.email
return super(ReplyViewSet, self).create(request, *args, **kwargs)
"""
############################################################
#REST API for Category
......
......@@ -3,8 +3,9 @@ from django.views.generic.list import ListView
from django.views.generic.edit import CreateView, UpdateView
from django.views.generic.detail import DetailView
from django.urls import reverse_lazy
from blog.models import Post, Comment
from blog.forms import CommentForm
#from blog.models import Post, Comment
from blog.models import Post
#from blog.forms import CommentForm
from core.mixins import StafRequiredMixin
# Create your views here.
......
Markdown is supported
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