diff options
| author | Bobby <[email protected]> | 2023-03-26 01:43:15 -0400 |
|---|---|---|
| committer | Bobby <[email protected]> | 2023-03-26 01:43:15 -0400 |
| commit | d6a07e1d402cf60202e3533606ff87152bfe5172 (patch) | |
| tree | 65511c76b53b71e1ff502bc6931f3af5c17be94b /blog_admin | |
| parent | 8449f83a150fcb577ccaebc14f5d19e7f88ccb7b (diff) | |
| download | thatcomputerscientist-d6a07e1d402cf60202e3533606ff87152bfe5172.tar.xz thatcomputerscientist-d6a07e1d402cf60202e3533606ff87152bfe5172.zip | |
Editable Post dates
Diffstat (limited to 'blog_admin')
| -rw-r--r-- | blog_admin/views.py | 10 |
1 files changed, 6 insertions, 4 deletions
diff --git a/blog_admin/views.py b/blog_admin/views.py index 49e309a3..fd724faa 100644 --- a/blog_admin/views.py +++ b/blog_admin/views.py @@ -1,4 +1,4 @@ -import base64 +from datetime import datetime from django.shortcuts import render, redirect, reverse from django.contrib import messages from blog.models import Post, Category, Tag @@ -44,6 +44,7 @@ def new_post(request): slug = request.POST.get('slug') if request.POST.get('slug') else '' post_image = request.FILES['post_image'] if 'post_image' in request.FILES else None additional_tags = request.POST.get('additional_tags') if request.POST.get('additional_tags') else '' + post_date = request.POST.get('post_date') if request.POST.get('post_date') else datetime.now() if additional_tags: tags += additional_tags.split(',') @@ -57,6 +58,7 @@ def new_post(request): post.category = Category.objects.get(id = category) post.slug = slug post.tags.set([Tag.objects.get_or_create(name = tag.strip())[0] for tag in tags]) + post.date = post_date if post_image: post.post_image = post_image post.save() @@ -68,12 +70,12 @@ def new_post(request): else: if not title or not category or not tags or not post_image: messages.error(request, 'Fields marked with asterisk (*) are required.', extra_tags='new_post_message') - return_object = { 'title_value': title, 'category_value': category, 'tags_value': tags, 'slug_value': slug, 'post_image_value': post_image, 'all_tags': all_tags } + return_object = { 'title_value': title, 'category_value': category, 'tags_value': tags, 'slug_value': slug, 'post_image_value': post_image, 'all_tags': all_tags, 'post_date_value': post_date } return render(request, 'blog_admin/new_post.html', { 'title': 'New Post', 'categories': categories, 'return_object': return_object }) else: # create new post try: - post = Post.objects.create(title = title, category = Category.objects.get(id = category), slug = slug, author = request.user, post_image = post_image) + post = Post.objects.create(title = title, category = Category.objects.get(id = category), slug = slug, author = request.user, post_image = post_image, date = post_date) post.tags.set([Tag.objects.get_or_create(name = tag.strip())[0] for tag in tags]) post.save() return redirect(reverse('blog-admin:edit-post', kwargs = { 'slug': post.slug })) @@ -91,7 +93,7 @@ def new_post(request): mode = 'new' if mode == 'edit' and post_id: post_tags = [tag.name for tag in post.tags.all()] - post = { 'id': post.id, 'title': post.title, 'category': post.category.id, 'tags': post_tags, 'slug': post.slug, 'post_image': post.post_image, 'all_tags': all_tags } + post = { 'id': post.id, 'title': post.title, 'category': post.category.id, 'tags': post_tags, 'slug': post.slug, 'post_image': post.post_image, 'all_tags': all_tags, 'post_date': post.date } return render(request, 'blog_admin/new_post.html', { 'title': 'Edit Post', 'categories': categories, 'post': post, 'all_tags': all_tags }) return render(request, 'blog_admin/new_post.html', { 'title': 'Create New Post', 'categories': categories, 'all_tags': all_tags }) |
