Skip to content

Commit

Permalink
Added Articles app inside the project
Browse files Browse the repository at this point in the history
  • Loading branch information
pravee42 committed Jan 23, 2022
1 parent c2ddba4 commit a7e4dc0
Show file tree
Hide file tree
Showing 19 changed files with 85 additions and 11 deletions.
Binary file modified articles/__pycache__/admin.cpython-39.pyc
Binary file not shown.
Binary file modified articles/__pycache__/models.cpython-39.pyc
Binary file not shown.
Binary file added articles/__pycache__/serializers.cpython-39.pyc
Binary file not shown.
Binary file added articles/__pycache__/urls.cpython-39.pyc
Binary file not shown.
Binary file added articles/__pycache__/views.cpython-39.pyc
Binary file not shown.
1 change: 1 addition & 0 deletions articles/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@
from .models import *
# Register your models here.
admin.site.register(Articles)
admin.site.register(Comments)
23 changes: 23 additions & 0 deletions articles/migrations/0003_comments.py
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()),
],
),
]
18 changes: 18 additions & 0 deletions articles/migrations/0004_comments_article_id.py
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 not shown.
10 changes: 10 additions & 0 deletions articles/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
12 changes: 12 additions & 0 deletions articles/serializers.py
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__'
5 changes: 1 addition & 4 deletions articles/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,5 @@
from . import views

urlpatterns = [
path('', views.post, name="post"),
path('get/<str:pk>', views.get, name="get"),
path('delete/<int:pk>', views.delete, name="delete"),
path('update/<int:pk>', views.update, name="update")
path('', views.ArticlesClass.as_view())
]
23 changes: 17 additions & 6 deletions articles/views.py
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 modified db.sqlite3
Binary file not shown.
Binary file modified newsapi/__pycache__/settings.cpython-39.pyc
Binary file not shown.
Binary file modified newsapi/__pycache__/urls.cpython-39.pyc
Binary file not shown.
1 change: 1 addition & 0 deletions newsapi/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
'users',
'bookmarks',
'shared_news',
'articles'
]

MIDDLEWARE = [
Expand Down
3 changes: 2 additions & 1 deletion newsapi/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'))
]

0 comments on commit a7e4dc0

Please sign in to comment.