-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added Articles app inside the project
- Loading branch information
Showing
19 changed files
with
85 additions
and
11 deletions.
There are no files selected for viewing
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
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 |
---|---|---|
|
@@ -2,3 +2,4 @@ | |
from .models import * | ||
# Register your models here. | ||
admin.site.register(Articles) | ||
admin.site.register(Comments) |
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 3.2.6 on 2022-01-23 02:28 | ||
|
||
from django.db import migrations, models | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
('articles', '0002_rename_atricles_articles'), | ||
] | ||
|
||
operations = [ | ||
migrations.CreateModel( | ||
name='Comments', | ||
fields=[ | ||
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), | ||
('user', models.CharField(max_length=300)), | ||
('commented_date', models.DateField(auto_now_add=True)), | ||
('comment', models.CharField(max_length=10000)), | ||
('likes', models.IntegerField()), | ||
], | ||
), | ||
] |
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,18 @@ | ||
# Generated by Django 3.2.6 on 2022-01-23 02:32 | ||
|
||
from django.db import migrations, models | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
('articles', '0003_comments'), | ||
] | ||
|
||
operations = [ | ||
migrations.AddField( | ||
model_name='comments', | ||
name='article_id', | ||
field=models.IntegerField(default=0), | ||
), | ||
] |
Binary file not shown.
Binary file added
BIN
+576 Bytes
articles/migrations/__pycache__/0004_comments_article_id.cpython-39.pyc
Binary file not shown.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
from rest_framework import serializers | ||
from .models import Articles, Comments | ||
|
||
class ArticlesSerializers(serializers.ModelSerializer): | ||
class Meta: | ||
model = Articles | ||
fields = '__all__' | ||
|
||
class CommentsSerializer(serializers.ModelSerializer): | ||
class Meta: | ||
model = Comments | ||
fields = '__all__' |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,19 @@ | ||
from django.shortcuts import render | ||
from .models import * | ||
from .serializers import * | ||
from django.http import Http404 | ||
from rest_framework.response import Response | ||
from rest_framework.views import APIView | ||
from rest_framework import status | ||
|
||
# Create your views here. | ||
class ArticlesClass(APIView): | ||
def get(self, request, format=None): | ||
snippets = Articles.objects.all() | ||
serializer = ArticlesSerializers(snippets, many=True) | ||
|
||
|
||
@api_view(['GET']) | ||
def get(request): | ||
pass | ||
return Response(serializer.data) | ||
def post(self, request, format=None): | ||
serializer = ArticlesSerializers(data=request.data) | ||
if serializer.is_valid(): | ||
serializer.save() | ||
return Response(serializer.data, status=status.HTTP_201_CREATED) | ||
return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST) |
Binary file not shown.
Binary file not shown.
Binary file not shown.
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 |
---|---|---|
|
@@ -46,6 +46,7 @@ | |
'users', | ||
'bookmarks', | ||
'shared_news', | ||
'articles' | ||
] | ||
|
||
MIDDLEWARE = [ | ||
|
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