-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
15 changed files
with
742 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
# Generated by Django 2.1.5 on 2019-02-07 14:12 | ||
|
||
from django.db import migrations, models | ||
import django.db.models.deletion | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
initial = True | ||
|
||
dependencies = [ | ||
('profiles', '0001_initial'), | ||
('articles', '0001_initial'), | ||
] | ||
|
||
operations = [ | ||
migrations.CreateModel( | ||
name='Comment', | ||
fields=[ | ||
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), | ||
('body', models.TextField()), | ||
('created_at', models.DateTimeField(auto_now_add=True)), | ||
('updated_at', models.DateTimeField(auto_now=True, null=True)), | ||
('article', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='articles.Article')), | ||
('author', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='profiles.Profile')), | ||
], | ||
options={ | ||
'ordering': ['created_at'], | ||
}, | ||
), | ||
migrations.CreateModel( | ||
name='CommentReply', | ||
fields=[ | ||
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), | ||
('body', models.TextField()), | ||
('created_at', models.DateTimeField(auto_now_add=True)), | ||
('updated_at', models.DateTimeField(auto_now=True, null=True)), | ||
('author', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='profiles.Profile')), | ||
('comment', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='comments.Comment')), | ||
], | ||
options={ | ||
'ordering': ['created_at'], | ||
}, | ||
), | ||
] |
21 changes: 21 additions & 0 deletions
21
authors/apps/comments/migrations/0002_auto_20190211_1918.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
# Generated by Django 2.1.5 on 2019-02-11 19:18 | ||
|
||
from django.db import migrations | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
('comments', '0001_initial'), | ||
] | ||
|
||
operations = [ | ||
migrations.AlterModelOptions( | ||
name='comment', | ||
options={'ordering': ['-created_at']}, | ||
), | ||
migrations.AlterModelOptions( | ||
name='commentreply', | ||
options={'ordering': ['-created_at']}, | ||
), | ||
] |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
from django.db import models | ||
|
||
from ..profiles.models import Profile | ||
from ..articles.models import Article | ||
|
||
|
||
class Comment(models.Model): | ||
"""The model defines the Comments table as stored in the DB | ||
""" | ||
body = models.TextField() | ||
created_at = models.DateTimeField(auto_now_add=True) | ||
updated_at = models.DateTimeField(auto_now=True, null=True) | ||
author = models.ForeignKey(Profile, on_delete=models.CASCADE) | ||
article = models.ForeignKey(Article, on_delete=models.CASCADE) | ||
|
||
class Meta: | ||
""" | ||
Ensure that the comments are returned in the order they were created | ||
""" | ||
ordering = ['-created_at'] | ||
|
||
def __str__(self): | ||
return self.body | ||
|
||
|
||
class CommentReply(models.Model): | ||
"""The model defines the Comment-Replies table as stored in the DB | ||
""" | ||
body = models.TextField() | ||
created_at = models.DateTimeField(auto_now_add=True) | ||
updated_at = models.DateTimeField(auto_now=True, null=True) | ||
comment = models.ForeignKey(Comment, on_delete=models.CASCADE) | ||
author = models.ForeignKey(Profile, on_delete=models.CASCADE) | ||
|
||
class Meta: | ||
""" | ||
Ensure that the comment-replies are returned in the order they were | ||
created | ||
""" | ||
ordering = ['-created_at'] | ||
|
||
def __str__(self): | ||
return self.body |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
from rest_framework import serializers | ||
|
||
from .models import Comment, CommentReply | ||
from ..profiles import serializers as ProfileSerializers | ||
|
||
|
||
class CommentSerializer(serializers.ModelSerializer): | ||
"""This serializer class specifies fields to render to the user | ||
for reteriving, updating or creating of a comment on an article. | ||
It specifies the author, article, created_at and updated_at fields | ||
as read-only since these fields data is auto generated | ||
""" | ||
author = ProfileSerializers.ProfileSerializer(read_only=True) | ||
|
||
class Meta: | ||
model = Comment | ||
fields = ( | ||
"created_at", | ||
"updated_at", | ||
"body", | ||
"author", | ||
"article", | ||
"id" | ||
) | ||
read_only_fields = ( | ||
"article", | ||
"author", | ||
"created_at", | ||
'updated_at' | ||
"id" | ||
) | ||
|
||
|
||
class CommentReplySerializer(serializers.ModelSerializer): | ||
"""This serializer class specifies fields to render to the user for | ||
reteriving,updating or creating of a reply to a comment. It specifies | ||
the author, comment,created_at and updated_at fields as read-only | ||
since these fields data is auto generated | ||
""" | ||
author = ProfileSerializers.ProfileSerializer(read_only=True) | ||
|
||
class Meta: | ||
model = CommentReply | ||
fields = ( | ||
"comment", | ||
"created_at", | ||
"updated_at", | ||
"body", | ||
"author", | ||
"id" | ||
) | ||
read_only_fields = ( | ||
'author', | ||
'created_at', | ||
'updated_at', | ||
'comment', | ||
"id" | ||
) |
Empty file.
Oops, something went wrong.