diff --git a/articles/__pycache__/admin.cpython-39.pyc b/articles/__pycache__/admin.cpython-39.pyc index e89a0d2..07ece65 100644 Binary files a/articles/__pycache__/admin.cpython-39.pyc and b/articles/__pycache__/admin.cpython-39.pyc differ diff --git a/articles/__pycache__/models.cpython-39.pyc b/articles/__pycache__/models.cpython-39.pyc index 6191f1b..a3f50aa 100644 Binary files a/articles/__pycache__/models.cpython-39.pyc and b/articles/__pycache__/models.cpython-39.pyc differ diff --git a/articles/__pycache__/serializers.cpython-39.pyc b/articles/__pycache__/serializers.cpython-39.pyc new file mode 100644 index 0000000..0d7ae20 Binary files /dev/null and b/articles/__pycache__/serializers.cpython-39.pyc differ diff --git a/articles/__pycache__/urls.cpython-39.pyc b/articles/__pycache__/urls.cpython-39.pyc new file mode 100644 index 0000000..3e52f03 Binary files /dev/null and b/articles/__pycache__/urls.cpython-39.pyc differ diff --git a/articles/__pycache__/views.cpython-39.pyc b/articles/__pycache__/views.cpython-39.pyc new file mode 100644 index 0000000..87c68d1 Binary files /dev/null and b/articles/__pycache__/views.cpython-39.pyc differ diff --git a/articles/admin.py b/articles/admin.py index 0ceb097..c523d40 100644 --- a/articles/admin.py +++ b/articles/admin.py @@ -2,3 +2,4 @@ from .models import * # Register your models here. admin.site.register(Articles) +admin.site.register(Comments) diff --git a/articles/migrations/0003_comments.py b/articles/migrations/0003_comments.py new file mode 100644 index 0000000..db878c6 --- /dev/null +++ b/articles/migrations/0003_comments.py @@ -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()), + ], + ), + ] diff --git a/articles/migrations/0004_comments_article_id.py b/articles/migrations/0004_comments_article_id.py new file mode 100644 index 0000000..35f6b35 --- /dev/null +++ b/articles/migrations/0004_comments_article_id.py @@ -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), + ), + ] diff --git a/articles/migrations/__pycache__/0003_comments.cpython-39.pyc b/articles/migrations/__pycache__/0003_comments.cpython-39.pyc new file mode 100644 index 0000000..1d64038 Binary files /dev/null and b/articles/migrations/__pycache__/0003_comments.cpython-39.pyc differ diff --git a/articles/migrations/__pycache__/0004_comments_article_id.cpython-39.pyc b/articles/migrations/__pycache__/0004_comments_article_id.cpython-39.pyc new file mode 100644 index 0000000..19da19a Binary files /dev/null and b/articles/migrations/__pycache__/0004_comments_article_id.cpython-39.pyc differ diff --git a/articles/models.py b/articles/models.py index 9c14a83..9c8022b 100644 --- a/articles/models.py +++ b/articles/models.py @@ -12,3 +12,13 @@ class Articles(models.Model): def __str__(self): return self.title + +class Comments(models.Model): + user = models.CharField(max_length=300) + article_id = models.IntegerField(default=0) + commented_date = models.DateField(auto_now_add=True) + comment = models.CharField(max_length=10000) + likes = models.IntegerField() + + def __str__(self): + return self.user \ No newline at end of file diff --git a/articles/serializers.py b/articles/serializers.py index e69de29..307b017 100644 --- a/articles/serializers.py +++ b/articles/serializers.py @@ -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__' \ No newline at end of file diff --git a/articles/urls.py b/articles/urls.py index 7b58a26..fbf03a5 100644 --- a/articles/urls.py +++ b/articles/urls.py @@ -3,8 +3,5 @@ from . import views urlpatterns = [ - path('', views.post, name="post"), - path('get/', views.get, name="get"), - path('delete/', views.delete, name="delete"), - path('update/', views.update, name="update") + path('', views.ArticlesClass.as_view()) ] diff --git a/articles/views.py b/articles/views.py index e7e2de1..2aa4fe2 100644 --- a/articles/views.py +++ b/articles/views.py @@ -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) \ No newline at end of file diff --git a/db.sqlite3 b/db.sqlite3 index 97409f4..a9556ce 100644 Binary files a/db.sqlite3 and b/db.sqlite3 differ diff --git a/newsapi/__pycache__/settings.cpython-39.pyc b/newsapi/__pycache__/settings.cpython-39.pyc index ac1de3c..29dfe06 100644 Binary files a/newsapi/__pycache__/settings.cpython-39.pyc and b/newsapi/__pycache__/settings.cpython-39.pyc differ diff --git a/newsapi/__pycache__/urls.cpython-39.pyc b/newsapi/__pycache__/urls.cpython-39.pyc index 6d66aff..df7ec7a 100644 Binary files a/newsapi/__pycache__/urls.cpython-39.pyc and b/newsapi/__pycache__/urls.cpython-39.pyc differ diff --git a/newsapi/settings.py b/newsapi/settings.py index 2ac2e73..445e529 100644 --- a/newsapi/settings.py +++ b/newsapi/settings.py @@ -46,6 +46,7 @@ 'users', 'bookmarks', 'shared_news', + 'articles' ] MIDDLEWARE = [ diff --git a/newsapi/urls.py b/newsapi/urls.py index f9d2200..5d41b51 100644 --- a/newsapi/urls.py +++ b/newsapi/urls.py @@ -21,5 +21,6 @@ path('', include('newsapp.urls')), path('auth', include('users.urls')), path('bookmark/', include('bookmarks.urls')), - path('share/', include('shared_news.urls')) + path('share/', include('shared_news.urls')), + path('articles/', include('articles.urls')) ]