From f47718852131c085aa2feb41d05a11faed305f9e Mon Sep 17 00:00:00 2001 From: Piotr Szkudlarek Date: Sun, 7 Jan 2024 01:10:31 +0100 Subject: [PATCH] Add ckeditor to post creation page --- .../migrations/0004_alter_post_content.py | 18 ++++++++++++++ ..._comment_date_added_alter_post_date_pub.py | 22 ++++++++++++++++++ PlanktonDetector/Community/models.py | 7 +++--- PlanktonDetector/Community/views.py | 2 +- PlanktonDetector/db.sqlite3 | Bin 479232 -> 479232 bytes .../static/Community/css/add_post.css | 13 +++++++---- .../static/Community/css/list_posts.css | 1 + .../static/Community/css/post_details.css | 3 ++- PlanktonDetector/templates/add_post.html | 3 ++- PlanktonDetector/templates/history.html | 2 +- PlanktonDetector/templates/post_details.html | 6 +++-- 11 files changed, 63 insertions(+), 14 deletions(-) create mode 100644 PlanktonDetector/Community/migrations/0004_alter_post_content.py create mode 100644 PlanktonDetector/Community/migrations/0005_alter_comment_date_added_alter_post_date_pub.py diff --git a/PlanktonDetector/Community/migrations/0004_alter_post_content.py b/PlanktonDetector/Community/migrations/0004_alter_post_content.py new file mode 100644 index 0000000..0233ee2 --- /dev/null +++ b/PlanktonDetector/Community/migrations/0004_alter_post_content.py @@ -0,0 +1,18 @@ +# Generated by Django 4.2.7 on 2024-01-06 23:25 + +import ckeditor.fields +from django.db import migrations + + +class Migration(migrations.Migration): + dependencies = [ + ("Community", "0003_comment_date_added"), + ] + + operations = [ + migrations.AlterField( + model_name="post", + name="content", + field=ckeditor.fields.RichTextField(blank=True, null=True), + ), + ] diff --git a/PlanktonDetector/Community/migrations/0005_alter_comment_date_added_alter_post_date_pub.py b/PlanktonDetector/Community/migrations/0005_alter_comment_date_added_alter_post_date_pub.py new file mode 100644 index 0000000..e7460ee --- /dev/null +++ b/PlanktonDetector/Community/migrations/0005_alter_comment_date_added_alter_post_date_pub.py @@ -0,0 +1,22 @@ +# Generated by Django 4.2.7 on 2024-01-07 00:00 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + dependencies = [ + ("Community", "0004_alter_post_content"), + ] + + operations = [ + migrations.AlterField( + model_name="comment", + name="date_added", + field=models.DateTimeField(auto_now_add=True), + ), + migrations.AlterField( + model_name="post", + name="date_pub", + field=models.DateTimeField(auto_now_add=True), + ), + ] diff --git a/PlanktonDetector/Community/models.py b/PlanktonDetector/Community/models.py index fa94610..8d8b78c 100644 --- a/PlanktonDetector/Community/models.py +++ b/PlanktonDetector/Community/models.py @@ -1,14 +1,15 @@ from django.db import models from django.contrib.auth.models import User +from ckeditor.fields import RichTextField # Create your models here. class Post(models.Model): title = models.CharField(max_length=500) - content = models.TextField() + content = RichTextField(null=True, blank=True) author = models.ForeignKey(User, on_delete=models.CASCADE, null=False) - date_pub = models.DateField(auto_now_add=True) + date_pub = models.DateTimeField(auto_now_add=True) @property def sorted_comments(self): @@ -19,4 +20,4 @@ class Comment(models.Model): author = models.ForeignKey(User, on_delete=models.CASCADE, null=False) content = models.TextField() post = models.ForeignKey(Post, on_delete=models.CASCADE) - date_added = models.DateField(auto_now_add=True) + date_added = models.DateTimeField(auto_now_add=True) diff --git a/PlanktonDetector/Community/views.py b/PlanktonDetector/Community/views.py index d3f1bf4..341c051 100644 --- a/PlanktonDetector/Community/views.py +++ b/PlanktonDetector/Community/views.py @@ -11,7 +11,7 @@ from .froms import PostForm, CommentForm class ListPosts(ListView): model = Post template_name = "list_posts.html" - paginate_by = 3 + paginate_by = 4 def get_queryset(self) -> QuerySet[Any]: queryset = Post.objects.all().order_by("-date_pub") diff --git a/PlanktonDetector/db.sqlite3 b/PlanktonDetector/db.sqlite3 index d4ec1d5f11e24a2377aa8cb78181c9554acd220b..a7d5506efc40ae13484e0682acaa14f07722aec3 100644 GIT binary patch delta 3230 zcmcImYi!%r73L)+Qj#U!*iD*;=Z1d8Noq@^-jXG|PP;W-;yf25^0GOUNJ+FLQW5D$ zR+}mIyrx(;Khh1u)?(NOWGHqi z$!@%~=!RkhANQVf?s($_s)hG#GhB zZBX;$aX0Js_OV&AjBcOD8T5JFo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x-<(I#02rOQx_qL>e%KfC}-vwP7X{#kVR+U5PNhQ2>C~a|Bt=AX{|_1tm|OG z3vkYu*mM9}_d8HxI}2X`E4wre1uQlVq3iP?DPoJ9)bVYY1Wx-A^yC*1?GUSICByTm zowsU*=#>rPSB;`S|31ShwC0I7U%!7!eB>U_jWawTE$F3P;*d#eR6_drt5V;m+`tSs zP+kK&O=Fo(S {% csrf_token %} - {{ form.as_p }} + {{form}} + {{form.media}} {%endblock content%} \ No newline at end of file diff --git a/PlanktonDetector/templates/history.html b/PlanktonDetector/templates/history.html index 5f610ae..9263579 100644 --- a/PlanktonDetector/templates/history.html +++ b/PlanktonDetector/templates/history.html @@ -12,7 +12,7 @@
upload_image
-

{{detection.date_predicted.date}}

+

{{detection.date_predicted}}

{{detection.owner}}

Images uploaded: {{detection.images.all.count}}

diff --git a/PlanktonDetector/templates/post_details.html b/PlanktonDetector/templates/post_details.html index b085729..a505834 100644 --- a/PlanktonDetector/templates/post_details.html +++ b/PlanktonDetector/templates/post_details.html @@ -8,20 +8,22 @@

{{object.title}}

-

{{object.content}}

+

{{object.content|safe}}

{{object.author}}

Comments:

-
+ {%if user.is_authenticated%} +
{%csrf_token%} {{form}}
+ {%endif%}
{%for comment in object.sorted_comments%}