From dab0dfc81b7758b2902eedf804ee49a11cdbfad5 Mon Sep 17 00:00:00 2001 From: Hamish Willee Date: Fri, 2 Feb 2018 14:42:12 +1100 Subject: [PATCH] Update assessment to Django2 --- blog/models.py | 3 +++ blog/tests/test_views.py | 2 +- blog/urls.py | 14 +++++++------- django_diy_blog/settings.py | 16 ++++++++-------- django_diy_blog/urls.py | 26 ++++++++++++++------------ django_diy_blog/wsgi.py | 2 +- requirements.txt | 6 ++++++ 7 files changed, 40 insertions(+), 29 deletions(-) create mode 100644 requirements.txt diff --git a/blog/models.py b/blog/models.py index 127db29..39b2ee7 100644 --- a/blog/models.py +++ b/blog/models.py @@ -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): """ diff --git a/blog/tests/test_views.py b/blog/tests/test_views.py index a1c03e7..6739ccc 100644 --- a/blog/tests/test_views.py +++ b/blog/tests/test_views.py @@ -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): diff --git a/blog/urls.py b/blog/urls.py index 29d529a..6e7bb44 100644 --- a/blog/urls.py +++ b/blog/urls.py @@ -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\d+)$', views.BlogListbyAuthorView.as_view(), name='blogs-by-author'), - url(r'^blog/(?P\d+)$', views.BlogDetailView.as_view(), name='blog-detail'), - url(r'^bloggers/$', views.BloggerListView.as_view(), name='bloggers'), - url(r'^blog/(?P\d+)/comment/$', views.BlogCommentCreate.as_view(), name='blog_comment'), + path('', views.index, name='index'), + path('blogs/', views.BlogListView.as_view(), name='blogs'), + path('blogger/', views.BlogListbyAuthorView.as_view(), name='blogs-by-author'), + path('blog/', views.BlogDetailView.as_view(), name='blog-detail'), + path('bloggers/', views.BloggerListView.as_view(), name='bloggers'), + path('blog//comment/', views.BlogCommentCreate.as_view(), name='blog_comment'), ] \ No newline at end of file diff --git a/django_diy_blog/settings.py b/django_diy_blog/settings.py index 84572a7..d48edee 100644 --- a/django_diy_blog/settings.py +++ b/django_diy_blog/settings.py @@ -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 @@ -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' @@ -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': { @@ -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 = [ { @@ -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' @@ -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/' diff --git a/django_diy_blog/urls.py b/django_diy_blog/urls.py index 1225f37..ff649d4 100644 --- a/django_diy_blog/urls.py +++ b/django_diy_blog/urls.py @@ -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')), ] diff --git a/django_diy_blog/wsgi.py b/django_diy_blog/wsgi.py index 83c99bf..d15f609 100644 --- a/django_diy_blog/wsgi.py +++ b/django_diy_blog/wsgi.py @@ -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 diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..ef3fa3b --- /dev/null +++ b/requirements.txt @@ -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 \ No newline at end of file