Skip to content

Commit d827540

Browse files
committed
fourth commit
1 parent 0ad10eb commit d827540

File tree

7 files changed

+80
-20
lines changed

7 files changed

+80
-20
lines changed

blog/models.py

+11-3
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
from django.utils import timezone
33
from django.contrib.auth.models import User
44
from django.urls import reverse
5+
56
class Post(models.Model):
67
title=models.CharField(max_length=100)
78
content=models.TextField()
@@ -18,9 +19,12 @@ def total_likes(self):
1819
return self.likes.count()
1920
def total_dislikes(self):
2021
return self.dislikes.count()
21-
22+
23+
def total_comment(self):
24+
return self.comment_set.count()
25+
2226
class Comment(models.Model):
23-
post=models.ForeignKey(Post, on_delete=models.CASCADE)
27+
post=models.ForeignKey(Post, on_delete=models.CASCADE,related_name='comment_set')
2428
comment=models.TextField(max_length=400)
2529
date_posted=models.DateTimeField(default=timezone.now)
2630
author=models.ForeignKey(User, on_delete=models.CASCADE, default="1")
@@ -32,4 +36,8 @@ def __str__(self):
3236
return self.comment[:60]
3337

3438
def get_absolute_url(self):
35-
return reverse('post-detail', kwargs={'pk': self.pk})
39+
return reverse('post-detail', kwargs={'pk': self.pk})
40+
41+
42+
43+

blog/static/blog/change.js

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
documnet.querySelectorAll('.accordion__button').forEach(button => {
2+
button.addEventListener('click', () => {
3+
const accordionContent = button.nextElementSibling;
4+
button.classList.toggle('accordion__button--active');
5+
if (button.classList.contains('accordion__button--active')) {
6+
accordionContent.style.maxHeight = accordionContent.scrollHeight + 'px';
7+
}
8+
else {
9+
accordionContent.style.maxHeight = 0;
10+
}
11+
});
12+
13+
});

blog/static/blog/main.css

+29
Original file line numberDiff line numberDiff line change
@@ -114,3 +114,32 @@ a.article-title:hover {
114114
max-height: 100vh;
115115
max-width:100%;
116116
}
117+
118+
/* .accordion__button{
119+
display:block;
120+
width:100%;
121+
padding:15px;
122+
border:none;
123+
outline:none;
124+
cursor:pointer;
125+
background:rgb(165, 0, 0);
126+
color:white;
127+
text-align:left;
128+
/* transition: background 0.2s ; */
129+
130+
/* .accordion__button::after{
131+
132+
float:right;
133+
translate:scale(1.5);
134+
}
135+
.accordion__button--active{
136+
background:black;
137+
138+
}
139+
.accordion__content{
140+
141+
overflow: hidden;
142+
max-height:0;
143+
transition: max-height 0.2s;
144+
145+
} */

blog/templates/blog/base.html

+4-3
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
<header class="site-header">
2323
<nav class="navbar navbar-expand-md navbar-dark bg-steel fixed-top">
2424
<div class="container">
25-
<a class="navbar-brand mr-4" href="{% url 'blog-home'%}">MessageBoard</a>
25+
2626
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarToggle"
2727
aria-controls="navbarToggle" aria-expanded="false" aria-label="Toggle navigation">
2828
<span class="navbar-toggler-icon"></span>
@@ -31,6 +31,7 @@
3131
<div class="navbar-nav mr-auto">
3232
<a class="nav-item nav-link" href="{% url 'homepage' %}">Home</a>
3333
<a class="nav-item nav-link" href="{% url 'blog-about' %}">About Us</a>
34+
<a class="nav-item nav-link" href="{% url 'blog-home'%}">MessageBoard</a>
3435
</div>
3536
<!-- Navbar Right Side -->
3637
<div class="navbar-nav">
@@ -77,7 +78,7 @@
7778

7879

7980
<div class="media" style="display:inline-block; height:max-content">
80-
<img class="rounded-circle account-img" style="border: 1px solid black;" src="{{user.profile.image.url}}">
81+
<img class="rounded-circle account-img" src="{{user.profile.image.url}}">
8182
<div class="media-body mr-2" style=" display:inline-block;height:max-content">
8283
<h3 >{{user.username}}</h3>
8384
<p class="text-secondary">{{user.email}}</p>
@@ -118,7 +119,7 @@ <h3 class="ml-5 "><a href="{% url 'register'%}" >Register today!</a></h3>
118119
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.min.js"
119120
integrity="sha384-JZR6Spejh4U02d8jOt6vLEHfe/JQGiRRSQQxSfFWpi1MquVdAyjUar5+76PVCmYl"
120121
crossorigin="anonymous"></script>
121-
<script src="{% static 'blog/check.js' %}"></script>
122+
<script src="{% static 'blog/change.js' %}"></script>
122123
</body>
123124

124125
</html>

blog/templates/blog/home.html

+2-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ <h2><a class="article-title" href="{% url 'post-detail' post.id %}">{{ post.titl
1919
<p class="article-content">{{ post.content }}</p>
2020

2121

22-
<!--<small style="float:inline-end"><a href="{% url 'post-detail' post.id %}">{{post.total_comments}} Comments</a></small>-->
22+
<small><a href="{% url 'post-detail' post.id %}" style="color:rgb(192, 16, 51)">{{post.total_comment}} Comments</a></small>
2323

2424
</div>
2525
<div>
@@ -41,6 +41,7 @@ <h2><a class="article-title" href="{% url 'post-detail' post.id %}">{{ post.titl
4141
<button class="btn btn-danger">{{post.total_dislikes}}<i class="fa fa-angle-down" aria-hidden="true"></i></button>
4242
{% endif %}
4343
</div>
44+
4445
</article>
4546
{% endfor %}
4647
{% if is_paginated %}

blog/templates/blog/index.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
<li><a href="{% url 'homepage' %}">Home</a></li>
3737
<li><a href="{% url 'blog-about' %}">About Us</a></li>
3838
<li><a href="{% url 'blog-home' %}">Messageboard</a></li>
39-
<li><button type="button" class="btn btn-outline-light me-2 lb" ><a href="{% url 'login' %}">Login</a></button></li>
39+
<li><button type="button" class="btn btn-outline-light me-2 lb" ><a href="{% url 'login' %} ">Login</a></button></li>
4040
<li><button type="button" class="btn btn-primary"><a href="{% url 'register' %} " id="reg">Sign-up</a></button></li>
4141
</ul>
4242
</div>

blog/templates/blog/post_detail.html

+20-12
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,24 @@
22
{% load crispy_forms_tags %}
33
{% block content %}
44

5-
<article class="media content-section">
5+
<article class="media content-section" >
6+
67
<img crossorigin="anonymous" class="rounded-circle article-img" src="{{object.author.profile.image.url}}">
8+
79
<div class="media-body">
810
<div class="article-metadata">
911
<a class="mr-2" href="{% url 'user-posts' object.author.username %}">{{ object.author }}</a>
1012
<small class="text-muted">{{ post.date_posted|date:"F d, Y" }}</small>
13+
<a href="{% url 'blog-home' %}" class="btn btn-secondary mb-5 "
14+
style="position:absolute;right:0;box-shadow: -2px 10px 12px rgba(0, 0, 0,1);" id="back">Back</a>
1115
{% if object.author == user %}
1216
<div>
13-
<a class="btn btn-secondary btn-sm mt-1 mb-1" href="{% url 'post-update' object.id %}">Update</a>
14-
<a class="btn btn-danger btn-sm mt-1 mb-1" href="{% url 'post-delete' object.id %}">Delete</a>
17+
<a class="btn btn-secondary btn-sm mt-1 mb-1" href="{% url 'post-update' object.id %}">Update</a>
18+
<a class="btn btn-danger btn-sm mt-1 mb-1" href="{% url 'post-delete' object.id %}">Delete</a>
1519
</div>
1620
{% endif %}
1721
</div>
22+
1823
<h2 class="article-title" >{{object.title }}</h2>
1924
{% if object.image %}
2025
<img class="post-img" src="{{object.image.url}}">
@@ -40,11 +45,11 @@ <h2 class="article-title" >{{object.title }}</h2>
4045

4146
{% endif %}
4247
</ul>
43-
48+
4449
<br><br>
45-
<a href="{% url 'blog-home' %}" class="btn btn-secondary mb-5">Back</a>
4650

47-
<h5>Comments</h5><br>
51+
<hr>
52+
<small>{{object.total_comment}} Comments</small><br>
4853
<br>
4954
<div>
5055
{%for comment in post.comment_set.all %}
@@ -53,8 +58,8 @@ <h5>Comments</h5><br>
5358
<p>{{comment.comment}}</p><hr>
5459
{%endfor%}
5560
</div>
56-
<br>
57-
<div class="content-section">
61+
62+
<div class="content-section" >
5863
{%if user.is_authenticated%}
5964
<form method="POST">
6065
{%csrf_token%}
@@ -63,15 +68,18 @@ <h5>Comments</h5><br>
6368
{{form|crispy}}
6469
</fieldset>
6570
<div class="form-group">
66-
<button class="btn btn-outline-info" type="submit">Post</button>
71+
<button class="btn btn-outline-danger" type="submit">Post</button>
6772
</div>
6873
</form>
6974
{%else %}
7075
Log In to comment
71-
</div>
72-
{%endif%}
73-
</div>
76+
77+
{%endif%}
78+
</div>
79+
80+
7481

7582
</article>
7683

84+
7785
{% endblock content %}

0 commit comments

Comments
 (0)