Skip to content

Commit a8ddd4c

Browse files
authored
Merge pull request mdn#73 from mdn/update_to_3_1_2
Updates Example to use Django 3.1.2
2 parents 6118f08 + a290f24 commit a8ddd4c

8 files changed

Lines changed: 36 additions & 23 deletions

File tree

‎.gitignore‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ var/
3030
*.egg-info/
3131
.installed.cfg
3232
*.egg
33+
staticfiles/
3334

3435
# PyInstaller
3536
# Usually these files are written by a python script from a template

‎catalog/models.py‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,9 @@ class Book(models.Model):
4141
# ManyToManyField used because a genre can contain many books and a Book can cover many genres.
4242
# Genre class has already been defined so we can specify the object above.
4343
language = models.ForeignKey('Language', on_delete=models.SET_NULL, null=True)
44+
45+
class Meta:
46+
ordering = ['title', 'author']
4447

4548
def display_genre(self):
4649
"""Creates a string for the Genre. This is required to display genre in Admin."""

‎locallibrary/settings.py‎

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,23 @@
1-
"""Django settings for locallibrary project.
1+
"""
2+
Django settings for locallibrary project.
23
3-
Generated by 'django-admin startproject' using Django 2.1.5.
4+
Generated by 'django-admin startproject' using Django 3.1.2.
45
56
For more information on this file, see
6-
https://docs.djangoproject.com/en/2.1/topics/settings/
7+
https://docs.djangoproject.com/en/3.1/topics/settings/
78
89
For the full list of settings and their values, see
9-
https://docs.djangoproject.com/en/2.1/ref/settings/
10+
https://docs.djangoproject.com/en/3.1/ref/settings/
1011
"""
1112

12-
import os
13+
from pathlib import Path
1314

14-
# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
15-
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
15+
# Build paths inside the project like this: BASE_DIR / 'subdir'.
16+
BASE_DIR = Path(__file__).resolve().parent.parent
1617

1718

1819
# Quick-start development settings - unsuitable for production
19-
# See https://docs.djangoproject.com/en/2.1/howto/deployment/checklist/
20+
# See https://docs.djangoproject.com/en/3.1/howto/deployment/checklist/
2021

2122
# SECURITY WARNING: keep the secret key used in production secret!
2223
#SECRET_KEY = 'cg#p$g+j9tax!#a3cup@1$8obt2_+&k3q+pmu)5%asj6yjpkag'
@@ -77,18 +78,18 @@
7778

7879

7980
# Database
80-
# https://docs.djangoproject.com/en/2.1/ref/settings/#databases
81+
# https://docs.djangoproject.com/en/3.1/ref/settings/#databases
8182

8283
DATABASES = {
8384
'default': {
8485
'ENGINE': 'django.db.backends.sqlite3',
85-
'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
86+
'NAME': BASE_DIR / 'db.sqlite3',
8687
}
8788
}
8889

8990

9091
# Password validation
91-
# https://docs.djangoproject.com/en/2.1/ref/settings/#auth-password-validators
92+
# https://docs.djangoproject.com/en/3.1/ref/settings/#auth-password-validators
9293

9394
AUTH_PASSWORD_VALIDATORS = [
9495
{
@@ -107,7 +108,7 @@
107108

108109

109110
# Internationalization
110-
# https://docs.djangoproject.com/en/2.1/topics/i18n/
111+
# https://docs.djangoproject.com/en/3.1/topics/i18n/
111112

112113
LANGUAGE_CODE = 'en-us'
113114

@@ -137,9 +138,9 @@
137138

138139

139140
# Static files (CSS, JavaScript, Images)
140-
# https://docs.djangoproject.com/en/2.1/howto/static-files/
141+
# https://docs.djangoproject.com/en/3.1/howto/static-files/
141142
# The absolute path to the directory where collectstatic will collect static files for deployment.
142-
STATIC_ROOT = os.path.join(BASE_DIR, 'staticfiles')
143+
STATIC_ROOT = BASE_DIR / 'staticfiles' #. os.path.join(BASE_DIR, 'staticfiles')
143144
# The URL to use when referring to static files (where they will be served from)
144145
STATIC_URL = '/static/'
145146

‎locallibrary/urls.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
"""locallibrary URL Configuration
22
33
The `urlpatterns` list routes URLs to views. For more information please see:
4-
https://docs.djangoproject.com/en/2.1/topics/http/urls/
4+
https://docs.djangoproject.com/en/3.1/topics/http/urls/
55
Examples:
66
Function views
77
1. Add an import: from my_app import views

‎locallibrary/wsgi.py‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
1-
"""WSGI config for locallibrary project.
1+
"""
2+
WSGI config for locallibrary project.
23
34
It exposes the WSGI callable as a module-level variable named ``application``.
45
56
For more information on this file, see
6-
https://docs.djangoproject.com/en/2.1/howto/deployment/wsgi/
7+
https://docs.djangoproject.com/en/3.1/howto/deployment/wsgi/
78
"""
89

910
import os

‎manage.py‎

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
11
#!/usr/bin/env python
2+
"""Django's command-line utility for administrative tasks."""
23
import os
34
import sys
45

5-
if __name__ == '__main__':
6+
7+
def main():
8+
"""Run administrative tasks."""
69
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'locallibrary.settings')
710
try:
811
from django.core.management import execute_from_command_line
@@ -13,3 +16,7 @@
1316
"forget to activate a virtual environment?"
1417
) from exc
1518
execute_from_command_line(sys.argv)
19+
20+
21+
if __name__ == '__main__':
22+
main()

‎requirements.txt‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
dj-database-url==0.5.0
2-
Django==2.1.5
3-
gunicorn==19.9.0
2+
Django==3.1.2
3+
gunicorn==20.0.4
44
psycopg2-binary==2.8.6
5-
wheel==0.30.0
6-
whitenoise==4.1.2
5+
wheel==0.35.1
6+
whitenoise==5.2.0

‎runtime.txt‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
python-3.7.0
1+
python-3.8.6

0 commit comments

Comments
 (0)