Skip to content

Commit

Permalink
Update assessment to Django2
Browse files Browse the repository at this point in the history
  • Loading branch information
hamishwillee committed Feb 2, 2018
1 parent 7d5385b commit dab0dfc
Show file tree
Hide file tree
Showing 7 changed files with 40 additions and 29 deletions.
3 changes: 3 additions & 0 deletions blog/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ class BlogAuthor(models.Model):
"""
user = models.ForeignKey(User, on_delete=models.SET_NULL, null=True)
bio = models.TextField(max_length=400, help_text="Enter your bio details here.")

class Meta:
ordering = ["user","bio"]

def get_absolute_url(self):
"""
Expand Down
2 changes: 1 addition & 1 deletion blog/tests/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@


from blog.models import Blog, BlogAuthor
from django.core.urlresolvers import reverse
from django.urls import reverse
from django.contrib.auth.models import User #Blog author or commenter

class BlogListView(TestCase):
Expand Down
14 changes: 7 additions & 7 deletions blog/urls.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
from django.conf.urls import url
from django.urls import path

from . import views


urlpatterns = [
url(r'^$', views.index, name='index'),
url(r'^blogs/$', views.BlogListView.as_view(), name='blogs'),
url(r'^blogger/(?P<pk>\d+)$', views.BlogListbyAuthorView.as_view(), name='blogs-by-author'),
url(r'^blog/(?P<pk>\d+)$', views.BlogDetailView.as_view(), name='blog-detail'),
url(r'^bloggers/$', views.BloggerListView.as_view(), name='bloggers'),
url(r'^blog/(?P<pk>\d+)/comment/$', views.BlogCommentCreate.as_view(), name='blog_comment'),
path('', views.index, name='index'),
path('blogs/', views.BlogListView.as_view(), name='blogs'),
path('blogger/<int:pk>', views.BlogListbyAuthorView.as_view(), name='blogs-by-author'),
path('blog/<int:pk>', views.BlogDetailView.as_view(), name='blog-detail'),
path('bloggers/', views.BloggerListView.as_view(), name='bloggers'),
path('blog/<int:pk>/comment/', views.BlogCommentCreate.as_view(), name='blog_comment'),
]
16 changes: 8 additions & 8 deletions django_diy_blog/settings.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
"""
Django settings for django_diy_blog project.
Generated by 'django-admin startproject' using Django 1.10.2.
Generated by 'django-admin startproject' using Django 2.0.
For more information on this file, see
https://docs.djangoproject.com/en/1.10/topics/settings/
https://docs.djangoproject.com/en/2.0/topics/settings/
For the full list of settings and their values, see
https://docs.djangoproject.com/en/1.10/ref/settings/
https://docs.djangoproject.com/en/2.0/ref/settings/
"""

import os
Expand All @@ -17,7 +17,7 @@


# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/1.10/howto/deployment/checklist/
# See https://docs.djangoproject.com/en/2.0/howto/deployment/checklist/

# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = 'u4dmr-4j6pb92jjv=phmvus%4*ld#jh06xa&fv)+$w$^_a8gu5'
Expand Down Expand Up @@ -73,7 +73,7 @@


# Database
# https://docs.djangoproject.com/en/1.10/ref/settings/#databases
# https://docs.djangoproject.com/en/2.0/ref/settings/#databases

DATABASES = {
'default': {
Expand All @@ -84,7 +84,7 @@


# Password validation
# https://docs.djangoproject.com/en/1.10/ref/settings/#auth-password-validators
# https://docs.djangoproject.com/en/2.0/ref/settings/#auth-password-validators

AUTH_PASSWORD_VALIDATORS = [
{
Expand All @@ -103,7 +103,7 @@


# Internationalization
# https://docs.djangoproject.com/en/1.10/topics/i18n/
# https://docs.djangoproject.com/en/2.0/topics/i18n/

LANGUAGE_CODE = 'en-us'

Expand All @@ -117,6 +117,6 @@


# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/1.10/howto/static-files/
# https://docs.djangoproject.com/en/2.0/howto/static-files/

STATIC_URL = '/static/'
26 changes: 14 additions & 12 deletions django_diy_blog/urls.py
Original file line number Diff line number Diff line change
@@ -1,43 +1,45 @@
"""django_diy_blog URL Configuration
The `urlpatterns` list routes URLs to views. For more information please see:
https://docs.djangoproject.com/en/1.10/topics/http/urls/
https://docs.djangoproject.com/en/2.0/topics/http/urls/
Examples:
Function views
1. Add an import: from my_app import views
2. Add a URL to urlpatterns: url(r'^$', views.home, name='home')
2. Add a URL to urlpatterns: path('', views.home, name='home')
Class-based views
1. Add an import: from other_app.views import Home
2. Add a URL to urlpatterns: url(r'^$', Home.as_view(), name='home')
2. Add a URL to urlpatterns: path('', Home.as_view(), name='home')
Including another URLconf
1. Import the include() function: from django.conf.urls import url, include
2. Add a URL to urlpatterns: url(r'^blog/', include('blog.urls'))
1. Import the include() function: from django.urls import include, path
2. Add a URL to urlpatterns: path('blog/', include('blog.urls'))
"""
from django.conf.urls import url

from django.contrib import admin
from django.urls import path

urlpatterns = [
url(r'^admin/', admin.site.urls),
path('admin/', admin.site.urls),
]


# Use include() to add URLS from the blog application
from django.conf.urls import include
from django.urls import include

urlpatterns += [
url(r'^blog/', include('blog.urls')),
path('blog/', include('blog.urls')),
]


#Add URL maps to redirect the base URL to our application
from django.views.generic import RedirectView
urlpatterns += [
url(r'^$', RedirectView.as_view(url='/blog/', permanent=True)),
path('', RedirectView.as_view(url='/blog/', permanent=True)),
]


#Add Django site authentication URLs (for login, logout, password management)
#Add Django site authentication urls (for login, logout, password management)
urlpatterns += [
url('^accounts/', include('django.contrib.auth.urls')),
path('accounts/', include('django.contrib.auth.urls')),
]


Expand Down
2 changes: 1 addition & 1 deletion django_diy_blog/wsgi.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
It exposes the WSGI callable as a module-level variable named ``application``.
For more information on this file, see
https://docs.djangoproject.com/en/1.10/howto/deployment/wsgi/
https://docs.djangoproject.com/en/2.0/howto/deployment/wsgi/
"""

import os
Expand Down
6 changes: 6 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
dj-database-url==0.4.2
Django==2.0.2
gunicorn==19.7.1
psycopg2==2.7.3.2
wheel==0.30.0
whitenoise==3.3.1

0 comments on commit dab0dfc

Please sign in to comment.