Skip to content

Commit ccc9e1b

Browse files
authored
Merge pull request #132 from Prakhar19999/upvote_downvote
Blog App
2 parents d4b980e + e8595ca commit ccc9e1b

34 files changed

+3122
-25
lines changed

.gitignore

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,3 +71,10 @@ venv.bak/
7171
__pycache__/
7272
website/db.sqlite3
7373

74+
# Migration files
75+
website/blog/migrations/
76+
website/events/migrations/
77+
website/forum/migrations/
78+
website/interview_exp/migrations/
79+
website/team/migrations/
80+
website/user_profile/migrations/

requirements.txt

912 Bytes
Binary file not shown.

website/blog/__init__.py

Whitespace-only changes.

website/blog/admin.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
from django.contrib import admin
2+
from .models import *
3+
4+
blog_models=[Posts,Likes,Taggings,Tags,Comment_Reply,Comment,Reply,PostLikes]
5+
admin.site.register(blog_models)

website/blog/apps.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
from django.apps import AppConfig
2+
3+
4+
class BlogConfig(AppConfig):
5+
name = 'blog'

website/blog/forms.py

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
from django import forms
2+
from .models import *
3+
from django.contrib.auth.models import User
4+
from django.utils.translation import ugettext as _
5+
import mimetypes
6+
from .validators import *
7+
from django.contrib.auth.forms import UserCreationForm
8+
from markdownx.fields import MarkdownxFormField
9+
from markdownx.utils import markdownify
10+
11+
class Postform(forms.ModelForm):
12+
title = models.CharField(max_length=100)
13+
description = MarkdownxFormField()
14+
15+
def clean_description(self):
16+
data = self.cleaned_data['description']
17+
print(len(data)<20)
18+
if len(data)<20:
19+
raise forms.ValidationError("Description too Short! Less than 20 words!")
20+
data = markdownify(data)
21+
return data
22+
23+
class Meta:
24+
model = Posts
25+
fields = ('title', 'description')
26+
27+
28+
class Tagsform(forms.ModelForm):
29+
name = models.CharField(max_length=100, null=True, blank=True)
30+
31+
class Meta:
32+
model = Tags
33+
fields = ('name',)
34+
35+
36+
class Taggingform(forms.ModelForm):
37+
class Meta:
38+
model = Taggings
39+
fields = ('post', 'tag')
40+
41+
class Replyform(forms.ModelForm):
42+
description = MarkdownxFormField()
43+
44+
def clean_description(self):
45+
data = self.cleaned_data['description']
46+
data = markdownify(data)
47+
return data
48+
49+
50+
class Meta:
51+
model = Reply
52+
fields = ('description',)
53+
54+
class Commentform(forms.ModelForm):
55+
body = MarkdownxFormField()
56+
57+
def clean_body(self):
58+
data = self.cleaned_data['body']
59+
data = markdownify(data)
60+
return data
61+
62+
class Meta:
63+
model = Comment
64+
fields = ('body',)
65+
66+
class Comment_Replyform(forms.ModelForm):
67+
body = MarkdownxFormField()
68+
69+
def clean_body(self):
70+
data = self.cleaned_data['body']
71+
data = markdownify(data)
72+
return data
73+
74+
class Meta:
75+
model = Comment_Reply
76+
fields = ('body',)
77+
78+
class SearchForm(forms.Form):
79+
key = forms.CharField(max_length=25)

website/blog/models.py

Lines changed: 139 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,139 @@
1+
from django.db import models
2+
from django.contrib.auth.models import User
3+
from django.contrib.auth import get_user_model
4+
from django.db.models.signals import post_save
5+
from django.dispatch import receiver
6+
7+
# Done
8+
class Posts(models.Model):
9+
title = models.CharField(max_length=100)
10+
description = models.TextField(blank=True, null=True)
11+
created_at = models.DateTimeField(auto_now=False, auto_now_add=True)
12+
updated_at = models.DateTimeField(auto_now=True, auto_now_add=False)
13+
user_id = models.ForeignKey(User, on_delete=models.CASCADE)
14+
15+
def __str__(self):
16+
return self.title
17+
18+
def get_cname(self):
19+
class_name = "Post"
20+
return class_name
21+
22+
class Meta:
23+
verbose_name_plural="Posts"
24+
25+
class Reply(models.Model):
26+
description = models.TextField(blank=True)
27+
created_at = models.DateTimeField(auto_now=False, auto_now_add=True)
28+
updated_at = models.DateTimeField(auto_now=True, auto_now_add=False)
29+
user_id = models.ForeignKey(User, on_delete=models.CASCADE)
30+
post_id = models.ForeignKey(Posts, on_delete=models.CASCADE)
31+
32+
def __str__(self):
33+
return self.description
34+
35+
def get_cname(self):
36+
class_name = "Reply"
37+
return class_name
38+
39+
class Meta:
40+
verbose_name_plural="Reply"
41+
42+
43+
class Comment(models.Model):
44+
body = models.TextField()
45+
user = models.ForeignKey(User, on_delete=models.CASCADE)
46+
post = models.ForeignKey(Posts, on_delete=models.CASCADE)
47+
# TO DO
48+
# AUTOGEN DATETIME
49+
created_at = models.DateTimeField(auto_now=False, auto_now_add=True)
50+
updated_at = models.DateTimeField(auto_now=True, auto_now_add=False)
51+
52+
def __str__(self):
53+
return self.body
54+
55+
def get_cname(self):
56+
class_name = "C"
57+
return class_name
58+
59+
class Meta:
60+
verbose_name_plural="Comment"
61+
62+
63+
64+
class Comment_Reply(models.Model):
65+
body = models.TextField()
66+
user = models.ForeignKey(User, on_delete=models.CASCADE)
67+
reply = models.ForeignKey(Reply, on_delete=models.CASCADE)
68+
created_at = models.DateTimeField(auto_now=False, auto_now_add=True)
69+
updated_at = models.DateTimeField(auto_now=True, auto_now_add=False)
70+
71+
def __str__(self):
72+
return self.body
73+
74+
def get_cname(self):
75+
class_name = "Comment_Reply"
76+
return class_name
77+
class Meta:
78+
verbose_name_plural="Comment_Reply"
79+
80+
81+
class Tags(models.Model):
82+
name = models.CharField(max_length=30, blank=True, null=True)
83+
created_at = models.DateTimeField(auto_now=False, auto_now_add=True)
84+
updated_at = models.DateTimeField(auto_now=True, auto_now_add=False)
85+
86+
def __str__(self):
87+
if self.name== None:
88+
return "None"
89+
else:
90+
return self.name
91+
class Meta:
92+
verbose_name_plural="Tags"
93+
94+
95+
96+
97+
98+
class Taggings(models.Model):
99+
post = models.ForeignKey(Posts, on_delete=models.CASCADE, blank=True, null=True)
100+
tag = models.ForeignKey(Tags, on_delete=models.CASCADE, blank=True, null=True)
101+
created_at = models.DateTimeField(auto_now=False, auto_now_add=True)
102+
updated_at = models.DateTimeField(auto_now=True, auto_now_add=False)
103+
104+
def __str__(self):
105+
return self.post.title + " : " + self.tag.name
106+
107+
class Meta:
108+
verbose_name_plural="Taggings"
109+
110+
111+
class Likes(models.Model):
112+
user = models.ForeignKey(User, on_delete=models.CASCADE)
113+
reply = models.ForeignKey(Reply, on_delete=models.CASCADE)
114+
# TBD
115+
created_at = models.DateTimeField(auto_now=False, auto_now_add=True)
116+
updated_at = models.DateTimeField(auto_now=True, auto_now_add=False)
117+
value = models.BooleanField(null=True,blank=True)
118+
119+
def __self__(self):
120+
return self.user
121+
122+
class Meta:
123+
verbose_name_plural="Comment_Likes"
124+
125+
126+
127+
class PostLikes(models.Model):
128+
user = models.ForeignKey(User, on_delete=models.CASCADE)
129+
post = models.ForeignKey(Posts, on_delete=models.CASCADE)
130+
# TBD
131+
created_at = models.DateTimeField(auto_now=False, auto_now_add=True)
132+
updated_at = models.DateTimeField(auto_now=True, auto_now_add=False)
133+
value = models.BooleanField(null=True,blank=True)
134+
135+
def __self__(self):
136+
return self.user
137+
138+
class Meta:
139+
verbose_name_plural="Post_Likes"

0 commit comments

Comments
 (0)