diff --git a/.idea/.gitignore b/.idea/.gitignore new file mode 100644 index 0000000..eaf91e2 --- /dev/null +++ b/.idea/.gitignore @@ -0,0 +1,3 @@ +# Default ignored files +/shelf/ +/workspace.xml diff --git a/.idea/Django_blog.iml b/.idea/Django_blog.iml new file mode 100644 index 0000000..a05f1a4 --- /dev/null +++ b/.idea/Django_blog.iml @@ -0,0 +1,11 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/inspectionProfiles/profiles_settings.xml b/.idea/inspectionProfiles/profiles_settings.xml new file mode 100644 index 0000000..105ce2d --- /dev/null +++ b/.idea/inspectionProfiles/profiles_settings.xml @@ -0,0 +1,6 @@ + + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 0000000..98b7183 --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,7 @@ + + + + + + \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml new file mode 100644 index 0000000..d417121 --- /dev/null +++ b/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000..c8397c9 --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/blog/migrations/0001_initial.py b/blog/migrations/0001_initial.py deleted file mode 100755 index 39ea4a9..0000000 --- a/blog/migrations/0001_initial.py +++ /dev/null @@ -1,48 +0,0 @@ -# Generated by Django 2.2.6 on 2019-10-13 10:21 - -from django.conf import settings -from django.db import migrations, models -import django.db.models.deletion - - -class Migration(migrations.Migration): - - initial = True - - dependencies = [ - migrations.swappable_dependency(settings.AUTH_USER_MODEL), - ] - - operations = [ - migrations.CreateModel( - name='Post', - fields=[ - ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), - ('title', models.CharField(max_length=200, unique=True)), - ('slug', models.SlugField(max_length=200, unique=True)), - ('updated_on', models.DateTimeField(auto_now=True)), - ('content', models.TextField()), - ('created_on', models.DateTimeField(auto_now_add=True)), - ('status', models.IntegerField(choices=[(0, 'Draft'), (1, 'Publish')], default=0)), - ('author', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='blog_posts', to=settings.AUTH_USER_MODEL)), - ], - options={ - 'ordering': ['-created_on'], - }, - ), - migrations.CreateModel( - name='Comment', - fields=[ - ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), - ('name', models.CharField(max_length=80)), - ('email', models.EmailField(max_length=254)), - ('body', models.TextField()), - ('created_on', models.DateTimeField(auto_now_add=True)), - ('status', models.IntegerField(choices=[(0, 'Draft'), (1, 'Publish')], default=0)), - ('post', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='comments', to='blog.Post')), - ], - options={ - 'ordering': ['created_on'], - }, - ), - ] diff --git a/blog/migrations/0002_comment_parent.py b/blog/migrations/0002_comment_parent.py deleted file mode 100755 index 34d10c1..0000000 --- a/blog/migrations/0002_comment_parent.py +++ /dev/null @@ -1,19 +0,0 @@ -# Generated by Django 2.2.6 on 2019-10-13 12:05 - -from django.db import migrations, models -import django.db.models.deletion - - -class Migration(migrations.Migration): - - dependencies = [ - ('blog', '0001_initial'), - ] - - operations = [ - migrations.AddField( - model_name='comment', - name='parent', - field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, related_name='replies', to='blog.Comment'), - ), - ] diff --git a/blog/migrations/0003_remove_comment_parent.py b/blog/migrations/0003_remove_comment_parent.py deleted file mode 100755 index d5a5ab3..0000000 --- a/blog/migrations/0003_remove_comment_parent.py +++ /dev/null @@ -1,17 +0,0 @@ -# Generated by Django 2.2.6 on 2019-10-13 14:16 - -from django.db import migrations - - -class Migration(migrations.Migration): - - dependencies = [ - ('blog', '0002_comment_parent'), - ] - - operations = [ - migrations.RemoveField( - model_name='comment', - name='parent', - ), - ] diff --git a/blog/migrations/0004_auto_20191015_0853.py b/blog/migrations/0004_auto_20191015_0853.py deleted file mode 100755 index 8aaef51..0000000 --- a/blog/migrations/0004_auto_20191015_0853.py +++ /dev/null @@ -1,22 +0,0 @@ -# Generated by Django 2.2.6 on 2019-10-15 08:53 - -from django.db import migrations, models - - -class Migration(migrations.Migration): - - dependencies = [ - ('blog', '0003_remove_comment_parent'), - ] - - operations = [ - migrations.RemoveField( - model_name='comment', - name='status', - ), - migrations.AddField( - model_name='comment', - name='active', - field=models.BooleanField(default=False), - ), - ] diff --git a/blog/migrations/0005_auto_20211014_1338.py b/blog/migrations/0005_auto_20211014_1338.py deleted file mode 100644 index c2b7110..0000000 --- a/blog/migrations/0005_auto_20211014_1338.py +++ /dev/null @@ -1,23 +0,0 @@ -# Generated by Django 3.2 on 2021-10-14 13:38 - -from django.db import migrations, models - - -class Migration(migrations.Migration): - - dependencies = [ - ('blog', '0004_auto_20191015_0853'), - ] - - operations = [ - migrations.AlterField( - model_name='comment', - name='id', - field=models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID'), - ), - migrations.AlterField( - model_name='post', - name='id', - field=models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID'), - ), - ] diff --git a/blog/__init__.py b/src/blog/__init__.py old mode 100755 new mode 100644 similarity index 100% rename from blog/__init__.py rename to src/blog/__init__.py diff --git a/blog/admin.py b/src/blog/admin.py old mode 100755 new mode 100644 similarity index 100% rename from blog/admin.py rename to src/blog/admin.py diff --git a/blog/apps.py b/src/blog/apps.py old mode 100755 new mode 100644 similarity index 100% rename from blog/apps.py rename to src/blog/apps.py diff --git a/blog/feeds.py b/src/blog/feeds.py similarity index 100% rename from blog/feeds.py rename to src/blog/feeds.py diff --git a/blog/forms.py b/src/blog/forms.py old mode 100755 new mode 100644 similarity index 100% rename from blog/forms.py rename to src/blog/forms.py diff --git a/blog/migrations/__init__.py b/src/blog/migrations/__init__.py old mode 100755 new mode 100644 similarity index 100% rename from blog/migrations/__init__.py rename to src/blog/migrations/__init__.py diff --git a/blog/models.py b/src/blog/models.py old mode 100755 new mode 100644 similarity index 95% rename from blog/models.py rename to src/blog/models.py index bd5695d..47d4de7 --- a/blog/models.py +++ b/src/blog/models.py @@ -14,6 +14,7 @@ class Post(models.Model): content = models.TextField() created_on = models.DateTimeField(auto_now_add=True) status = models.IntegerField(choices=STATUS, default=0) + tag = models.CharField(unique=False, max_length=50) class Meta: ordering = ["-created_on"] diff --git a/blog/sitemaps.py b/src/blog/sitemaps.py similarity index 100% rename from blog/sitemaps.py rename to src/blog/sitemaps.py diff --git a/blog/tests.py b/src/blog/tests.py old mode 100755 new mode 100644 similarity index 100% rename from blog/tests.py rename to src/blog/tests.py diff --git a/blog/urls.py b/src/blog/urls.py old mode 100755 new mode 100644 similarity index 71% rename from blog/urls.py rename to src/blog/urls.py index 9bc4613..1decfb6 --- a/blog/urls.py +++ b/src/blog/urls.py @@ -1,12 +1,15 @@ from django.urls import include, path from . import views +from blog.views import PostTag, AllPosts from .feeds import AtomSiteNewsFeed, LatestPostsFeed urlpatterns = [ path("feed/rss", LatestPostsFeed(), name="post_feed"), path("feed/atom", AtomSiteNewsFeed()), path("", views.PostList.as_view(), name="home"), + path("posts/", views.AllPosts.as_view(), name="articles"), # path('/', views.PostDetail.as_view(), name='post_detail'), path("/", views.post_detail, name="post_detail"), + path("posts//", PostTag.as_view(), name="post_tag") ] diff --git a/blog/views.py b/src/blog/views.py old mode 100755 new mode 100644 similarity index 68% rename from blog/views.py rename to src/blog/views.py index 863d3b6..5dcfe29 --- a/blog/views.py +++ b/src/blog/views.py @@ -1,4 +1,4 @@ -from django.shortcuts import get_object_or_404, render +from django.shortcuts import get_object_or_404, render, redirect from django.views import generic from .forms import CommentForm @@ -15,6 +15,18 @@ class PostList(generic.ListView): # model = Post # template_name = 'post_detail.html' +class PostTag(generic.ListView): + template_name = "index.html" + paginate_by = 3 + + def get_queryset(self): + posts = Post.objects.filter(tag=self.kwargs['tag']) + return posts + def get_context_data(self, *args, **kwargs): + context = super().get_context_data(*args, **kwargs) + context['tag'] = self.kwargs['tag'] + return context + def post_detail(request, slug): template_name = "post_detail.html" @@ -25,7 +37,6 @@ def post_detail(request, slug): if request.method == "POST": comment_form = CommentForm(data=request.POST) if comment_form.is_valid(): - # Create Comment object but don't save to database yet new_comment = comment_form.save(commit=False) # Assign the current post to the comment @@ -45,3 +56,9 @@ def post_detail(request, slug): "comment_form": comment_form, }, ) + + +class AllPosts(generic.ListView): + template_name = "index.html" + queryset = Post.objects.filter(status=1).order_by("-created_on") + paginate_by = 3 diff --git a/manage.py b/src/manage.py old mode 100755 new mode 100644 similarity index 100% rename from manage.py rename to src/manage.py diff --git a/mysite/__init__.py b/src/mysite/__init__.py old mode 100755 new mode 100644 similarity index 100% rename from mysite/__init__.py rename to src/mysite/__init__.py diff --git a/mysite/settings.py b/src/mysite/settings.py old mode 100755 new mode 100644 similarity index 99% rename from mysite/settings.py rename to src/mysite/settings.py index 7e6330e..9a52a3c --- a/mysite/settings.py +++ b/src/mysite/settings.py @@ -17,6 +17,8 @@ TEMPLATES_DIR = os.path.join(BASE_DIR, "templates") + + # Quick-start development settings - unsuitable for production # See https://docs.djangoproject.com/en/2.1/howto/deployment/checklist/ diff --git a/mysite/urls.py b/src/mysite/urls.py old mode 100755 new mode 100644 similarity index 99% rename from mysite/urls.py rename to src/mysite/urls.py index 4c3bd0e..dd9f6dc --- a/mysite/urls.py +++ b/src/mysite/urls.py @@ -19,7 +19,6 @@ from django.contrib.sitemaps.views import sitemap from django.urls import include, path import debug_toolbar - from blog.sitemaps import PostSitemap sitemaps = { diff --git a/mysite/wsgi.py b/src/mysite/wsgi.py old mode 100755 new mode 100644 similarity index 100% rename from mysite/wsgi.py rename to src/mysite/wsgi.py diff --git a/static/css/base.css b/src/static/css/base.css old mode 100755 new mode 100644 similarity index 88% rename from static/css/base.css rename to src/static/css/base.css index 62389f8..59c6963 --- a/static/css/base.css +++ b/src/static/css/base.css @@ -4,6 +4,12 @@ body { background-color: #fdfdfd; } +.post-tag { + color: black; + text-decoration: none; +} + + .shadow { box-shadow: 0 4px 2px -2px rgba(0, 0, 0, 0.1); } diff --git a/templates/base.html b/src/templates/base.html old mode 100755 new mode 100644 similarity index 100% rename from templates/base.html rename to src/templates/base.html diff --git a/templates/index.html b/src/templates/index.html old mode 100755 new mode 100644 similarity index 77% rename from templates/index.html rename to src/templates/index.html index 760ca1a..cc148c6 --- a/templates/index.html +++ b/src/templates/index.html @@ -9,27 +9,35 @@
+ + {% if "/posts/"|add:tag|add:"/" in request.path %} + +

Tag: {{tag}}

+ + {% elif "/posts/" in request.path %} +

all posts

+ + {% else %}

Welcome to my awesome Blog

-

We Love Django As much as you do   -

+

We Love Django As much as you do  

+ + {% endif %}
-
-
{% for post in post_list %}
+ {{ post.tag }}

{{ post.title }}

{{ post.author }} | {{ post.created_on}}

-

{{post.content|safe|slice:":200" }}

Read More →
diff --git a/templates/post_detail.html b/src/templates/post_detail.html old mode 100755 new mode 100644 similarity index 93% rename from templates/post_detail.html rename to src/templates/post_detail.html index e672195..3a3124a --- a/templates/post_detail.html +++ b/src/templates/post_detail.html @@ -8,6 +8,9 @@

{% block title %} {{ post.title }} {% endblock title %}

{{ post.author }} | {{ post.created_on }}

{{ post.content | safe }}

+
+

Tag

+ {{ post.tag }}
{% block sidebar %} {% include 'sidebar.html' %} {% endblock sidebar %} @@ -17,11 +20,9 @@

{% block title %} {{ post.title }} {% endblock title %}

{% with comments.count as total_comments %}

{{ total_comments }} comments

-

{% endwith %} {% for comment in comments %}

-

{{ comment.name }} diff --git a/templates/sidebar.html b/src/templates/sidebar.html old mode 100755 new mode 100644 similarity index 100% rename from templates/sidebar.html rename to src/templates/sidebar.html