-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #17 from andela/ft-crud-on-articles-162948842
#162948842 Have CRUD on Articles Resource
- Loading branch information
Showing
23 changed files
with
590 additions
and
0 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
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,3 @@ | ||
from django.contrib import admin | ||
|
||
# Register your models here. |
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,5 @@ | ||
from django.apps import AppConfig | ||
|
||
|
||
class ArticlesConfig(AppConfig): | ||
name = 'articles' |
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,32 @@ | ||
# Generated by Django 2.1.4 on 2019-01-17 09:11 | ||
|
||
import cloudinary.models | ||
from django.conf import settings | ||
from django.db import migrations, models | ||
import django.db.models.deletion | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
initial = True | ||
|
||
dependencies = [ | ||
migrations.swappable_dependency(settings.AUTH_USER_MODEL), | ||
] | ||
|
||
operations = [ | ||
migrations.CreateModel( | ||
name='Article', | ||
fields=[ | ||
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), | ||
('title', models.CharField(max_length=50, unique=True)), | ||
('body', models.TextField(unique=True)), | ||
('description', models.CharField(max_length=50)), | ||
('images', cloudinary.models.CloudinaryField(default='', max_length=255)), | ||
('created', models.DateTimeField(auto_now_add=True)), | ||
('modified', models.DateTimeField(auto_now=True)), | ||
('slug', models.SlugField()), | ||
('author', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL)), | ||
], | ||
), | ||
] |
28 changes: 28 additions & 0 deletions
28
authors/apps/articles/migrations/0002_auto_20190117_1653.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,28 @@ | ||
# Generated by Django 2.1.4 on 2019-01-17 16:53 | ||
|
||
from django.db import migrations, models | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
('articles', '0001_initial'), | ||
] | ||
|
||
operations = [ | ||
migrations.AddField( | ||
model_name='article', | ||
name='is_dispayed', | ||
field=models.BooleanField(default=True), | ||
), | ||
migrations.AlterField( | ||
model_name='article', | ||
name='slug', | ||
field=models.SlugField(unique=True), | ||
), | ||
migrations.AlterField( | ||
model_name='article', | ||
name='title', | ||
field=models.CharField(max_length=200), | ||
), | ||
] |
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,20 @@ | ||
# Generated by Django 2.1.4 on 2019-01-17 17:26 | ||
|
||
from django.db import migrations | ||
import taggit.managers | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
('taggit', '0002_auto_20150616_2121'), | ||
('articles', '0002_auto_20190117_1653'), | ||
] | ||
|
||
operations = [ | ||
migrations.AddField( | ||
model_name='article', | ||
name='tags', | ||
field=taggit.managers.TaggableManager(help_text='A comma-separated list of tags.', through='taggit.TaggedItem', to='taggit.Tag', verbose_name='Tags'), | ||
), | ||
] |
19 changes: 19 additions & 0 deletions
19
authors/apps/articles/migrations/0004_auto_20190117_1727.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,19 @@ | ||
# Generated by Django 2.1.4 on 2019-01-17 17:27 | ||
|
||
from django.db import migrations | ||
import taggit.managers | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
('articles', '0003_article_tags'), | ||
] | ||
|
||
operations = [ | ||
migrations.AlterField( | ||
model_name='article', | ||
name='tags', | ||
field=taggit.managers.TaggableManager(blank=True, help_text='A comma-separated list of tags.', through='taggit.TaggedItem', to='taggit.Tag', verbose_name='Tags'), | ||
), | ||
] |
19 changes: 19 additions & 0 deletions
19
authors/apps/articles/migrations/0005_auto_20190117_1744.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,19 @@ | ||
# Generated by Django 2.1.4 on 2019-01-17 17:44 | ||
|
||
import cloudinary.models | ||
from django.db import migrations | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
('articles', '0004_auto_20190117_1727'), | ||
] | ||
|
||
operations = [ | ||
migrations.AlterField( | ||
model_name='article', | ||
name='images', | ||
field=cloudinary.models.CloudinaryField(blank=True, max_length=255), | ||
), | ||
] |
23 changes: 23 additions & 0 deletions
23
authors/apps/articles/migrations/0006_auto_20190118_0703.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,23 @@ | ||
# Generated by Django 2.1.4 on 2019-01-18 07:03 | ||
|
||
import cloudinary.models | ||
from django.db import migrations | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
('articles', '0005_auto_20190117_1744'), | ||
] | ||
|
||
operations = [ | ||
migrations.RemoveField( | ||
model_name='article', | ||
name='tags', | ||
), | ||
migrations.AlterField( | ||
model_name='article', | ||
name='images', | ||
field=cloudinary.models.CloudinaryField(blank=True, default='', max_length=255, null=True), | ||
), | ||
] |
23 changes: 23 additions & 0 deletions
23
authors/apps/articles/migrations/0007_auto_20190120_1431.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,23 @@ | ||
# Generated by Django 2.1.4 on 2019-01-20 14:31 | ||
|
||
from django.db import migrations, models | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
('articles', '0006_auto_20190118_0703'), | ||
] | ||
|
||
operations = [ | ||
migrations.RenameField( | ||
model_name='article', | ||
old_name='is_dispayed', | ||
new_name='is_displayed', | ||
), | ||
migrations.AddField( | ||
model_name='article', | ||
name='is_published', | ||
field=models.BooleanField(default=False), | ||
), | ||
] |
22 changes: 22 additions & 0 deletions
22
authors/apps/articles/migrations/0008_auto_20190121_0751.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,22 @@ | ||
# Generated by Django 2.1.4 on 2019-01-21 07:51 | ||
|
||
from django.db import migrations, models | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
('articles', '0007_auto_20190120_1431'), | ||
] | ||
|
||
operations = [ | ||
migrations.RemoveField( | ||
model_name='article', | ||
name='is_displayed', | ||
), | ||
migrations.AddField( | ||
model_name='article', | ||
name='is_deleted', | ||
field=models.BooleanField(default=False), | ||
), | ||
] |
24 changes: 24 additions & 0 deletions
24
authors/apps/articles/migrations/0009_auto_20190121_0754.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,24 @@ | ||
# Generated by Django 2.1.4 on 2019-01-21 07:54 | ||
|
||
import cloudinary.models | ||
from django.db import migrations, models | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
('articles', '0008_auto_20190121_0751'), | ||
] | ||
|
||
operations = [ | ||
migrations.AlterField( | ||
model_name='article', | ||
name='body', | ||
field=models.TextField(), | ||
), | ||
migrations.AlterField( | ||
model_name='article', | ||
name='images', | ||
field=cloudinary.models.CloudinaryField(blank=True, default='No image', max_length=255, null=True), | ||
), | ||
] |
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,20 @@ | ||
from django.db import models | ||
from authors.apps.authentication.models import User | ||
|
||
from cloudinary.models import CloudinaryField | ||
|
||
|
||
class Article(models.Model): | ||
""" | ||
This is the Article model that is used to handle CRUD on articles | ||
""" | ||
title = models.CharField(max_length=200, blank=False) | ||
body = models.TextField(blank=False) | ||
description = models.CharField(max_length=50, blank=False) | ||
images = CloudinaryField(blank=True, default='No image', null=True) | ||
created = models.DateTimeField(auto_now_add=True) | ||
modified = models.DateTimeField(auto_now=True) | ||
slug = models.SlugField(max_length=50, blank=False, unique=True) | ||
is_deleted = models.BooleanField(default=False) | ||
is_published = models.BooleanField(default=False) | ||
author = models.ForeignKey(User, on_delete=models.CASCADE) |
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,64 @@ | ||
import re | ||
|
||
from rest_framework import serializers | ||
from .models import Article | ||
|
||
|
||
class ArticleSerializer(serializers.ModelSerializer): | ||
"""Serializers for creating and retrieving all articles""" | ||
# Field in the database corresponding to the User model | ||
author = serializers.SerializerMethodField() | ||
# Uploads an image to the Cloudinary servers | ||
images = serializers.ImageField(default=None) | ||
|
||
class Meta: | ||
model = Article | ||
fields = ['title', | ||
'slug', | ||
'description', | ||
'body', | ||
'created', | ||
'modified', | ||
'images', | ||
'author', | ||
'slug'] | ||
read_only_fields = ['created', | ||
'modified', | ||
'author', | ||
'slug', | ||
'images'] | ||
|
||
# Inserts the ID of the author of an article into the foreign key row | ||
def get_author(self, obj): | ||
return obj.author.id | ||
|
||
|
||
class GetArticleSerializer(serializers.ModelSerializer): | ||
"""Serializers for retrieving a single article and updating""" | ||
# Field in the database corresponding to the User model | ||
author = serializers.SerializerMethodField() | ||
# Uploads an image to the Cloudinary servers | ||
images = serializers.ImageField(default=None) | ||
|
||
class Meta: | ||
model = Article | ||
fields = ['title', | ||
'description', | ||
'body', | ||
'modified', | ||
'images', | ||
'author', | ||
'slug'] | ||
read_only_fields = ['modified', | ||
'author', | ||
'slug'] | ||
|
||
def get_author(self, obj): | ||
return obj.author.id | ||
|
||
|
||
class DeleteArticleSerializer(serializers.ModelSerializer): | ||
"""Serializer for deleting an article""" | ||
class Meta: | ||
model = Article | ||
fields = ['is_deleted'] |
Empty file.
Oops, something went wrong.