-
Notifications
You must be signed in to change notification settings - Fork 1
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
Anupamaraie
committed
Nov 4, 2023
1 parent
fb83056
commit e5302da
Showing
9 changed files
with
520 additions
and
9 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
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,3 +1,8 @@ | ||
from django.contrib import admin | ||
|
||
from .models import * | ||
|
||
# Register your models here. | ||
admin.site.register(Posts) | ||
admin.site.register(Comments) | ||
admin.site.register(Likes) |
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,93 @@ | ||
# Generated by Django 4.2.6 on 2023-10-28 08:21 | ||
|
||
from django.db import migrations, models | ||
import django.db.models.deletion | ||
|
||
|
||
class Migration(migrations.Migration): | ||
initial = True | ||
|
||
dependencies = [] | ||
|
||
operations = [ | ||
migrations.CreateModel( | ||
name="Users", | ||
fields=[ | ||
("user_id", models.AutoField(primary_key=True, serialize=False)), | ||
("username", models.CharField(max_length=50)), | ||
("email", models.EmailField(max_length=254, unique=True)), | ||
("password", models.CharField(max_length=10)), | ||
], | ||
), | ||
migrations.CreateModel( | ||
name="Posts", | ||
fields=[ | ||
("post_id", models.AutoField(primary_key=True, serialize=False)), | ||
("title", models.CharField(max_length=50)), | ||
("content", models.TextField()), | ||
("created_at", models.DateTimeField(auto_now_add=True)), | ||
("updated_at", models.DateTimeField(auto_now=True)), | ||
( | ||
"user", | ||
models.ForeignKey( | ||
on_delete=django.db.models.deletion.CASCADE, to="blogs.users" | ||
), | ||
), | ||
], | ||
), | ||
migrations.CreateModel( | ||
name="Likes", | ||
fields=[ | ||
( | ||
"id", | ||
models.BigAutoField( | ||
auto_created=True, | ||
primary_key=True, | ||
serialize=False, | ||
verbose_name="ID", | ||
), | ||
), | ||
("created_at", models.DateTimeField(auto_now=True)), | ||
( | ||
"post", | ||
models.ForeignKey( | ||
on_delete=django.db.models.deletion.CASCADE, to="blogs.posts" | ||
), | ||
), | ||
( | ||
"user", | ||
models.ForeignKey( | ||
on_delete=django.db.models.deletion.CASCADE, to="blogs.users" | ||
), | ||
), | ||
], | ||
), | ||
migrations.CreateModel( | ||
name="Comments", | ||
fields=[ | ||
( | ||
"id", | ||
models.BigAutoField( | ||
auto_created=True, | ||
primary_key=True, | ||
serialize=False, | ||
verbose_name="ID", | ||
), | ||
), | ||
("c_content", models.TextField()), | ||
("created_at", models.DateTimeField(auto_now=True)), | ||
( | ||
"post", | ||
models.ForeignKey( | ||
on_delete=django.db.models.deletion.CASCADE, to="blogs.posts" | ||
), | ||
), | ||
( | ||
"user", | ||
models.ForeignKey( | ||
on_delete=django.db.models.deletion.CASCADE, to="blogs.users" | ||
), | ||
), | ||
], | ||
), | ||
] |
63 changes: 63 additions & 0 deletions
63
blogs/migrations/0002_alter_comments_post_alter_comments_user_and_more.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,63 @@ | ||
# Generated by Django 4.2.6 on 2023-10-28 15:52 | ||
|
||
from django.conf import settings | ||
from django.db import migrations, models | ||
import django.db.models.deletion | ||
|
||
|
||
class Migration(migrations.Migration): | ||
dependencies = [ | ||
migrations.swappable_dependency(settings.AUTH_USER_MODEL), | ||
("blogs", "0001_initial"), | ||
] | ||
|
||
operations = [ | ||
migrations.AlterField( | ||
model_name="comments", | ||
name="post", | ||
field=models.ForeignKey( | ||
on_delete=django.db.models.deletion.CASCADE, | ||
related_name="comment_post", | ||
to="blogs.posts", | ||
), | ||
), | ||
migrations.AlterField( | ||
model_name="comments", | ||
name="user", | ||
field=models.ForeignKey( | ||
on_delete=django.db.models.deletion.CASCADE, | ||
related_name="comment_user", | ||
to=settings.AUTH_USER_MODEL, | ||
), | ||
), | ||
migrations.AlterField( | ||
model_name="likes", | ||
name="post", | ||
field=models.ForeignKey( | ||
on_delete=django.db.models.deletion.CASCADE, | ||
related_name="like_post", | ||
to="blogs.posts", | ||
), | ||
), | ||
migrations.AlterField( | ||
model_name="likes", | ||
name="user", | ||
field=models.ForeignKey( | ||
on_delete=django.db.models.deletion.CASCADE, | ||
related_name="like_user", | ||
to=settings.AUTH_USER_MODEL, | ||
), | ||
), | ||
migrations.AlterField( | ||
model_name="posts", | ||
name="user", | ||
field=models.ForeignKey( | ||
on_delete=django.db.models.deletion.CASCADE, | ||
related_name="post", | ||
to=settings.AUTH_USER_MODEL, | ||
), | ||
), | ||
migrations.DeleteModel( | ||
name="Users", | ||
), | ||
] |
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,3 +1,35 @@ | ||
from datetime import datetime | ||
|
||
from django.conf import settings | ||
from django.contrib.auth.models import User | ||
from django.db import models | ||
|
||
# Create your models here. | ||
|
||
|
||
class Posts(models.Model): | ||
post_id = models.AutoField(primary_key=True) | ||
title = models.CharField(max_length=50, blank=False) | ||
content = models.TextField(blank=False) | ||
created_at = models.DateTimeField(auto_now_add=True) | ||
updated_at = models.DateTimeField(auto_now=True) | ||
user = models.ForeignKey(settings.AUTH_USER_MODEL, on_delete=models.CASCADE, related_name='post') #reference from Users | ||
|
||
def __str__(self): | ||
return self.title | ||
|
||
|
||
class Comments(models.Model): | ||
post = models.ForeignKey(Posts, on_delete= models.CASCADE,related_name='comment_post') #reference from Posts | ||
user = models.ForeignKey(settings.AUTH_USER_MODEL, on_delete= models.CASCADE, related_name='comment_user') #reference from Users | ||
c_content = models.TextField() | ||
created_at = models.DateTimeField(auto_now=True) | ||
|
||
def __str__(self): | ||
return f"{self.user}/{self.post}" | ||
|
||
|
||
class Likes(models.Model): | ||
post = models.ForeignKey(Posts, on_delete= models.CASCADE, related_name='like_post') #refrence from Posts | ||
user = models.ForeignKey(settings.AUTH_USER_MODEL, on_delete= models.CASCADE, related_name='like_user') #reference from Users | ||
created_at = models.DateTimeField(auto_now=True) |
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,39 @@ | ||
from django.contrib.auth.models import User | ||
from rest_framework import serializers | ||
|
||
from authentication.serializers import * | ||
|
||
from .models import * | ||
|
||
|
||
class LikeSerializer(serializers.ModelSerializer): | ||
class Meta: | ||
model = Likes | ||
fields = '__all__' | ||
read_only_fields = ['user','post'] | ||
|
||
class CommentSerializer(serializers.ModelSerializer): | ||
class Meta: | ||
model = Comments | ||
fields = '__all__' | ||
read_only_fields = ['user'] | ||
|
||
class CommentEditSerializer(serializers.ModelSerializer): | ||
class Meta: | ||
model = Comments | ||
fields = '__all__' | ||
read_only_fields = ['user','post'] | ||
|
||
class PostSerializer(serializers.ModelSerializer): | ||
comment_post = CommentSerializer(many=True) | ||
like_post = LikeSerializer(many=True) | ||
user = serializers.CharField() | ||
class Meta: | ||
model = Posts | ||
fields = ('user','post_id','title','content','created_at','updated_at','comment_post','like_post') | ||
|
||
class CreatePostSerializer(serializers.ModelSerializer): | ||
class Meta: | ||
model = Posts | ||
fields = ('user','title','content') | ||
read_only_fields = ['user'] |
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 @@ | ||
from django.urls import include, path | ||
|
||
from blogs.views import (CreateBlogView, CreateCommentView, EditCommentView, | ||
GetBlogView, LikeCreateView, ReadCommentView, | ||
ReadPostView) | ||
|
||
urlpatterns = [ | ||
path('getblog',GetBlogView.as_view()), | ||
path('readpost/<int:post_id>',ReadPostView.as_view()), | ||
path('createblog',CreateBlogView.as_view()), | ||
path('createblog/<int:post_id>/',CreateBlogView.as_view()), | ||
path('deleteblog/<int:post_id>',CreateBlogView.as_view()), | ||
path('createcomment',CreateCommentView.as_view()), | ||
path('readcomment/<int:id>', ReadCommentView.as_view()), | ||
path('editcomment/<int:id>/',EditCommentView.as_view()), | ||
path('deletecomment/<int:id>',CreateCommentView.as_view()), | ||
path('likepost/<int:post_id>',LikeCreateView.as_view()), | ||
path('unlikepost/<int:post_id>',LikeCreateView.as_view()), | ||
] |
Oops, something went wrong.