diff --git a/.gitignore b/.gitignore
deleted file mode 100644
index 6f8f59b..0000000
--- a/.gitignore
+++ /dev/null
@@ -1,3 +0,0 @@
-*.pyc
-*.db
-*.sqlite3
diff --git a/blogging/__pycache__/__init__.cpython-36.pyc b/blogging/__pycache__/__init__.cpython-36.pyc
new file mode 100644
index 0000000..a1ca561
Binary files /dev/null and b/blogging/__pycache__/__init__.cpython-36.pyc differ
diff --git a/blogging/__pycache__/admin.cpython-36.pyc b/blogging/__pycache__/admin.cpython-36.pyc
new file mode 100644
index 0000000..40f0548
Binary files /dev/null and b/blogging/__pycache__/admin.cpython-36.pyc differ
diff --git a/blogging/__pycache__/models.cpython-36.pyc b/blogging/__pycache__/models.cpython-36.pyc
new file mode 100644
index 0000000..071eb71
Binary files /dev/null and b/blogging/__pycache__/models.cpython-36.pyc differ
diff --git a/blogging/__pycache__/tests.cpython-36.pyc b/blogging/__pycache__/tests.cpython-36.pyc
new file mode 100644
index 0000000..69f67ee
Binary files /dev/null and b/blogging/__pycache__/tests.cpython-36.pyc differ
diff --git a/blogging/__pycache__/urls.cpython-36.pyc b/blogging/__pycache__/urls.cpython-36.pyc
new file mode 100644
index 0000000..6a9d201
Binary files /dev/null and b/blogging/__pycache__/urls.cpython-36.pyc differ
diff --git a/blogging/__pycache__/views.cpython-36.pyc b/blogging/__pycache__/views.cpython-36.pyc
new file mode 100644
index 0000000..03fdb18
Binary files /dev/null and b/blogging/__pycache__/views.cpython-36.pyc differ
diff --git a/blogging/admin.py b/blogging/admin.py
index 1175916..3a35761 100644
--- a/blogging/admin.py
+++ b/blogging/admin.py
@@ -1,6 +1,6 @@
from django.contrib import admin
-from blogging.models import Post, Category
+from blogging.models import Post, Category
admin.site.register(Post)
-admin.site.register(Category)
+admin.site.register(Category)
\ No newline at end of file
diff --git a/blogging/fixtures/blogging_test_fixture.json b/blogging/fixtures/blogging_test_fixture.json
index bf5269e..d85425f 100644
--- a/blogging/fixtures/blogging_test_fixture.json
+++ b/blogging/fixtures/blogging_test_fixture.json
@@ -35,4 +35,4 @@
"date_joined": "2013-05-24T05:35:58.628Z"
}
}
-]
+]
\ No newline at end of file
diff --git a/blogging/migrations/0001_initial.py b/blogging/migrations/0001_initial.py
index 5d406bf..95e099a 100644
--- a/blogging/migrations/0001_initial.py
+++ b/blogging/migrations/0001_initial.py
@@ -1,4 +1,4 @@
-# Generated by Django 2.1.1 on 2019-10-29 01:39
+# Generated by Django 2.1.1 on 2020-05-18 15:31
from django.conf import settings
from django.db import migrations, models
diff --git a/blogging/migrations/0002_category.py b/blogging/migrations/0002_category.py
index 0ccbe19..2220df1 100644
--- a/blogging/migrations/0002_category.py
+++ b/blogging/migrations/0002_category.py
@@ -1,4 +1,4 @@
-# Generated by Django 2.1.1 on 2019-11-05 03:35
+# Generated by Django 2.1.1 on 2020-05-19 15:23
from django.db import migrations, models
diff --git a/blogging/migrations/0003_auto_20191104_1942.py b/blogging/migrations/0003_auto_20191104_1942.py
deleted file mode 100644
index 663c56d..0000000
--- a/blogging/migrations/0003_auto_20191104_1942.py
+++ /dev/null
@@ -1,17 +0,0 @@
-# Generated by Django 2.1.1 on 2019-11-05 03:42
-
-from django.db import migrations
-
-
-class Migration(migrations.Migration):
-
- dependencies = [
- ('blogging', '0002_category'),
- ]
-
- operations = [
- migrations.AlterModelOptions(
- name='category',
- options={'verbose_name_plural': 'Categories'},
- ),
- ]
diff --git a/blogging/migrations/__pycache__/0001_initial.cpython-36.pyc b/blogging/migrations/__pycache__/0001_initial.cpython-36.pyc
new file mode 100644
index 0000000..42fb473
Binary files /dev/null and b/blogging/migrations/__pycache__/0001_initial.cpython-36.pyc differ
diff --git a/blogging/migrations/__pycache__/0002_category.cpython-36.pyc b/blogging/migrations/__pycache__/0002_category.cpython-36.pyc
new file mode 100644
index 0000000..10745e3
Binary files /dev/null and b/blogging/migrations/__pycache__/0002_category.cpython-36.pyc differ
diff --git a/blogging/migrations/__pycache__/__init__.cpython-36.pyc b/blogging/migrations/__pycache__/__init__.cpython-36.pyc
new file mode 100644
index 0000000..146e2e9
Binary files /dev/null and b/blogging/migrations/__pycache__/__init__.cpython-36.pyc differ
diff --git a/blogging/models.py b/blogging/models.py
index 10d6cc3..d8b06fe 100644
--- a/blogging/models.py
+++ b/blogging/models.py
@@ -2,23 +2,25 @@
from django.contrib.auth.models import User
class Post(models.Model):
+
title = models.CharField(max_length=128)
text = models.TextField(blank=True)
author = models.ForeignKey(User, on_delete=models.CASCADE)
created_date = models.DateTimeField(auto_now_add=True)
modified_date = models.DateTimeField(auto_now=True)
published_date = models.DateTimeField(blank=True, null=True)
-
+
def __str__(self):
return self.title
-
+
class Category(models.Model):
+
name = models.CharField(max_length=128)
description = models.TextField(blank=True)
posts = models.ManyToManyField(Post, blank=True, related_name='categories')
-
- class Meta:
- verbose_name_plural = 'Categories'
-
+
def __str__(self):
return self.name
+
+ class Meta:
+ verbose_name_plural = 'Categories'
\ No newline at end of file
diff --git a/blogging/static/django_blog.css b/blogging/static/django_blog.css
index 45a882d..64560dc 100644
--- a/blogging/static/django_blog.css
+++ b/blogging/static/django_blog.css
@@ -71,4 +71,4 @@ ul.categories {
}
ul.categories li {
display: inline;
-}
+}
\ No newline at end of file
diff --git a/blogging/templates/blogging/detail.html b/blogging/templates/blogging/detail.html
index ea5b9c8..cfa7b96 100644
--- a/blogging/templates/blogging/detail.html
+++ b/blogging/templates/blogging/detail.html
@@ -14,4 +14,4 @@
-
-
- Posted by {{ post.author.username }} — {{ post.published_date }}
-
-
- {{ post.text }}
+
Recent Posts
+ {% comment %} here is where the query happens {% endcomment %}
+ {% for post in posts %}
+
+
+
+ Posted by {{ post.author.username }} — {{ post.published_date }}
+
+
+ {{ post.text }}
+
+
+ {% for category in post.categories.all %}
+ - {{ category }}
+ {% endfor %}
+
-
- {% for category in post.categories.all %}
- - {{ category }}
- {% endfor %}
-
-
- {% endfor %}
-{% endblock %}
+ {% endfor %}
+{% endblock %}
\ No newline at end of file
diff --git a/blogging/tests.py b/blogging/tests.py
index 4250226..1edc012 100644
--- a/blogging/tests.py
+++ b/blogging/tests.py
@@ -1,26 +1,22 @@
import datetime
-
+from django.utils.timezone import utc
from django.test import TestCase
from django.contrib.auth.models import User
-from django.utils.timezone import utc
-
from blogging.models import Post
from blogging.models import Category
-
class PostTestCase(TestCase):
fixtures = ['blogging_test_fixture.json', ]
def setUp(self):
self.user = User.objects.get(pk=1)
-
+
def test_string_representation(self):
expected = "This is a title"
p1 = Post(title=expected)
actual = str(p1)
self.assertEqual(expected, actual)
-
-
+
class CategoryTestCase(TestCase):
def test_string_representation(self):
@@ -28,8 +24,8 @@ def test_string_representation(self):
c1 = Category(name=expected)
actual = str(c1)
self.assertEqual(expected, actual)
-
-
+
+
class FrontEndTestCase(TestCase):
"""test views provided in the front-end"""
fixtures = ['blogging_test_fixture.json', ]
@@ -47,7 +43,7 @@ def setUp(self):
pubdate = self.now - self.timedelta * count
post.published_date = pubdate
post.save()
-
+
def test_list_only_published(self):
resp = self.client.get('/')
# the content of the rendered response is always a bytestring
@@ -59,7 +55,7 @@ def test_list_only_published(self):
self.assertContains(resp, title, count=1)
else:
self.assertNotContains(resp, title)
-
+
def test_details_only_published(self):
for count in range(1, 11):
title = "Post %d Title" % count
@@ -69,4 +65,4 @@ def test_details_only_published(self):
self.assertEqual(resp.status_code, 200)
self.assertContains(resp, title)
else:
- self.assertEqual(resp.status_code, 404)
+ self.assertEqual(resp.status_code, 404)
\ No newline at end of file
diff --git a/blogging/urls.py b/blogging/urls.py
index 172a39c..6e2c9cf 100644
--- a/blogging/urls.py
+++ b/blogging/urls.py
@@ -2,6 +2,6 @@
from blogging.views import list_view, detail_view
urlpatterns = [
- path('', list_view, name="blog_index"),
+ path('',list_view, name="blog_index"),
path('posts/
/', detail_view, name="blog_detail"),
-]
+]
\ No newline at end of file
diff --git a/blogging/views.py b/blogging/views.py
index b4bab4f..e07acea 100644
--- a/blogging/views.py
+++ b/blogging/views.py
@@ -1,9 +1,25 @@
-from django.shortcuts import render
from django.http import HttpResponse, HttpResponseRedirect, Http404
from django.template import loader
-
from blogging.models import Post
+from django.shortcuts import render
+def stub_view(request, *args, **kwargs):
+
+ body = "Stub View\n\n"
+ if args:
+ body += "Args:\n"
+ body += "\n".join(["\t%s" % a for a in args])
+ if kwargs:
+ body += "Kwargs:\n"
+ body += "\n".join(["\t%s: %s" % i for i in kwargs.items()])
+ return HttpResponse(body, content_type="text/plain")
+
+def list_view(request):
+
+ published = Post.objects.exclude(published_date__exact=None)
+ posts = published.order_by('-published_date')
+ context = {'posts': posts}
+ return render(request, 'blogging/list.html', context)
def detail_view(request, post_id):
published = Post.objects.exclude(published_date__exact=None)
@@ -12,11 +28,4 @@ def detail_view(request, post_id):
except Post.DoesNotExist:
raise Http404
context = {'post': post}
- return render(request, 'blogging/detail.html', context)
-
-
-def list_view(request):
- published = Post.objects.exclude(published_date__exact=None)
- posts = published.order_by('-published_date')
- context = {'posts': posts}
- return render(request, 'blogging/list.html', context)
+ return render(request, 'blogging/detail.html', context)
\ No newline at end of file
diff --git a/db.sqlite3 b/db.sqlite3
new file mode 100644
index 0000000..bc064bc
Binary files /dev/null and b/db.sqlite3 differ
diff --git a/mysite/__pycache__/__init__.cpython-36.pyc b/mysite/__pycache__/__init__.cpython-36.pyc
new file mode 100644
index 0000000..7f06be1
Binary files /dev/null and b/mysite/__pycache__/__init__.cpython-36.pyc differ
diff --git a/mysite/__pycache__/settings.cpython-36.pyc b/mysite/__pycache__/settings.cpython-36.pyc
new file mode 100644
index 0000000..42b1d0b
Binary files /dev/null and b/mysite/__pycache__/settings.cpython-36.pyc differ
diff --git a/mysite/__pycache__/urls.cpython-36.pyc b/mysite/__pycache__/urls.cpython-36.pyc
new file mode 100644
index 0000000..cbfdb15
Binary files /dev/null and b/mysite/__pycache__/urls.cpython-36.pyc differ
diff --git a/mysite/__pycache__/wsgi.cpython-36.pyc b/mysite/__pycache__/wsgi.cpython-36.pyc
new file mode 100644
index 0000000..b3d10e2
Binary files /dev/null and b/mysite/__pycache__/wsgi.cpython-36.pyc differ
diff --git a/mysite/settings.py b/mysite/settings.py
index 14e4a11..37831f4 100644
--- a/mysite/settings.py
+++ b/mysite/settings.py
@@ -20,7 +20,7 @@
# See https://docs.djangoproject.com/en/2.1/howto/deployment/checklist/
# SECURITY WARNING: keep the secret key used in production secret!
-SECRET_KEY = 'xak=ca*e6hvh8q5hgfz5l9ees)_pxjif0)ui!ikifg4!enjk+7'
+SECRET_KEY = '9@s4f=3pgo)l2(#*zoogaurq$#v*%bi1d9cmim1(z(2budl@!%'
# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True
@@ -120,6 +120,5 @@
# https://docs.djangoproject.com/en/2.1/howto/static-files/
STATIC_URL = '/static/'
-
LOGIN_URL = '/login/'
LOGIN_REDIRECT_URL = '/'
diff --git a/mysite/templates/base.html b/mysite/templates/base.html
index 4bb0230..666f998 100644
--- a/mysite/templates/base.html
+++ b/mysite/templates/base.html
@@ -1,27 +1,30 @@
{% load staticfiles %}
+
-
- My Django Blog
-
-
-
- {# header ends here #}
-
-
- {% block content %}
- [content will go here]
- {% endblock %}
-
-
-
-
+
+ My Django Blog
+
+
+
+
+
+
+
+
+ {% block content %}
+ [content will go here]
+ {% endblock %}
+
+
+
+