Skip to content

Commit 430be02

Browse files
danmozcrccheck
authored andcommitted
Add support for Django 2.0 (#85)
Adding support for Django 2.0+, and removing support for Django versions up to 1.8, the oldest supported LTS release. This allows us to replace the now deprecated django-extensions UUIDField with the Django native version, and drop a couple of other hacks. Resolves #84
1 parent 81af3e7 commit 430be02

File tree

9 files changed

+58
-57
lines changed

9 files changed

+58
-57
lines changed

.travis.yml

Lines changed: 32 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,37 @@
11
language: python
2-
# Workaround for Python 3.6 missing
3-
python: "3.6"
42
cache: pip
5-
# Generate this env list with:
6-
# tox -l | awk '{ print " - TOX_ENV="$0}'
7-
env:
8-
- TOX_ENV=django16-py27
9-
- TOX_ENV=django16-py33
10-
- TOX_ENV=django17-py27
11-
- TOX_ENV=django17-py33
12-
- TOX_ENV=django17-py34
13-
- TOX_ENV=django18-py27
14-
- TOX_ENV=django18-py34
15-
- TOX_ENV=django18-py35
16-
- TOX_ENV=django19-py27
17-
- TOX_ENV=django19-py34
18-
- TOX_ENV=django19-py35
19-
- TOX_ENV=django110-py27
20-
- TOX_ENV=django110-py35
21-
- TOX_ENV=django111-py27
22-
- TOX_ENV=django111-py35
23-
- TOX_ENV=django111-py36
24-
- TOX_ENV=coveralls-django111-py36
3+
4+
matrix:
5+
include:
6+
- python: 2.7
7+
env: TOX_ENV=django18-py27
8+
- python: 3.4
9+
env: TOX_ENV=django18-py34
10+
- python: 3.5
11+
env: TOX_ENV=django18-py35
12+
- python: 2.7
13+
env: TOX_ENV=django19-py27
14+
- python: 3.4
15+
env: TOX_ENV=django19-py34
16+
- python: 3.5
17+
env: TOX_ENV=django19-py35
18+
- python: 2.7
19+
env: TOX_ENV=django110-py27
20+
- python: 3.5
21+
env: TOX_ENV=django110-py35
22+
- python: 2.7
23+
env: TOX_ENV=django111-py27
24+
- python: 3.5
25+
env: TOX_ENV=django111-py35
26+
- python: 3.6
27+
env: TOX_ENV=django111-py36
28+
- python: 3.5
29+
env: TOX_ENV=django20-py35
30+
- python: 3.6
31+
env: TOX_ENV=django20-py36
32+
- python: 3.6
33+
env: TOX_ENV=coveralls-django111-py36
34+
2535
install: pip install tox coveralls
2636
script: tox -e $TOX_ENV
2737
after_success: coveralls

Makefile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ resetdb: ## Delete and then recreate the dev sqlite database
5050

5151
.PHONY: build
5252
build: ## Build a full set of Docker images
53-
build: build/1.11.1 build/1.10.7 build/1.9.13 build/1.8.18 build/1.7.11 build/1.6.11
53+
build: build/2.0 build/1.11.1 build/1.10.7 build/1.9.13 build/1.8.18
5454

5555
build/%:
5656
docker build --build-arg DJANGO_VERSION=$* \
@@ -62,6 +62,7 @@ run/%:
6262
docker run --rm -p 8000:8000 -it $(IMAGE):$*
6363

6464
docker/publish: ## Publish Docker images to the hub
65+
docker push $(IMAGE):2.0
6566
docker push $(IMAGE):1.11
6667
docker push $(IMAGE):1.10
6768
docker push $(IMAGE):1.9

example_project/polls/migrations/0001_initial.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44

55
from django.db import migrations, models
66
import django.db.models.deletion
7-
import django_extensions.db.fields
87

98

109
class Migration(migrations.Migration):
@@ -26,7 +25,7 @@ class Migration(migrations.Migration):
2625
migrations.CreateModel(
2726
name='Comment',
2827
fields=[
29-
('uuid', django_extensions.db.fields.UUIDField(blank=True, editable=False, primary_key=True, serialize=False)),
28+
('uuid', models.UUIDField(editable=False, primary_key=True, serialize=False)),
3029
('comment', models.TextField(blank=True, null=True)),
3130
],
3231
),

example_project/polls/models.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import datetime
2+
import uuid
23

34
from django.db import models
45
from django.utils import timezone
5-
from django_extensions.db.fields import UUIDField
66

77

88
class Poll(models.Model):
@@ -20,7 +20,7 @@ def was_published_recently(self):
2020

2121

2222
class Choice(models.Model):
23-
poll = models.ForeignKey(Poll)
23+
poll = models.ForeignKey(Poll, on_delete=models.CASCADE)
2424
choice_text = models.CharField(max_length=200)
2525
votes = models.IntegerField()
2626

@@ -29,7 +29,7 @@ def __unicode__(self):
2929

3030

3131
class Comment(models.Model):
32-
uuid = UUIDField(primary_key=True)
32+
uuid = models.UUIDField(primary_key=True, default=uuid.uuid4, editable=False)
3333
comment = models.TextField(null=True, blank=True)
3434

3535
def __unicode__(self):

example_project/settings.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,7 @@ def project_dir(*paths):
3636

3737
ROOT_URLCONF = 'example_project.urls'
3838

39-
40-
MIDDLEWARE_CLASSES = (
39+
MIDDLEWARE_CLASSES = MIDDLEWARE = (
4140
'django.contrib.sessions.middleware.SessionMiddleware',
4241
'django.middleware.common.CommonMiddleware',
4342
'django.middleware.csrf.CsrfViewMiddleware',

example_project/urls.py

Lines changed: 11 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,18 @@
1-
from django.conf import settings
2-
from django.conf.urls import include, url
1+
from django import VERSION
2+
from django.conf.urls import url
33
from django.contrib import admin
4-
from django.views.static import serve
5-
try:
6-
from django.conf.urls import patterns
7-
except ImportError:
8-
# DJANGO1.6 DJANGO1.7
9-
# https://docs.djangoproject.com/en/1.8/releases/1.8/#django-conf-urls-patterns
10-
def patterns(__, *urlpatterns):
11-
return urlpatterns
12-
134
from example_project.polls.admin import support_admin
145

6+
if VERSION[0] == 1 and VERSION[1] <= 8:
7+
from django.conf.urls import include
8+
else:
9+
# DJANGO1.9
10+
# https://docs.djangoproject.com/en/2.0/releases/1.9/#passing-a-3-tuple-or-an-app-name-to-include
11+
def include(urls):
12+
return urls
1513

16-
admin.autodiscover()
1714

18-
urlpatterns = patterns(
19-
'',
15+
urlpatterns = [
2016
url(r'^admin/', include(admin.site.urls)),
2117
url(r'^support/', include(support_admin.urls)),
22-
# serve media
23-
url(r'^media/(?P<path>.*)$', serve, {
24-
'document_root': settings.MEDIA_ROOT,
25-
}),
26-
)
18+
]

requirements.in

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
dj-database-url
2-
# Can upgrade once we lose DJANGO1.7
3-
django-extensions==1.6.7
2+
django-extensions==2.0.0
43
factory-boy
54
Faker
65
coverage
76
mock
7+
uuid

requirements.txt

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,12 @@
66
#
77
coverage==4.4.1
88
dj-database-url==0.4.2
9-
django-extensions==1.6.7
9+
django-extensions==2.0.0
1010
factory-boy==2.8.1
11-
faker==0.7.17 # via factory-boy
11+
faker==0.7.17
1212
mock==2.0.0
1313
pbr==3.0.1 # via mock
1414
python-dateutil==2.6.0 # via faker
1515
six==1.10.0 # via django-extensions, faker, mock, python-dateutil
16+
typing==3.6.4 # via django-extensions
17+
uuid==1.30

tox.ini

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,11 @@
22
# https://docs.djangoproject.com/en/dev/faq/install/#what-python-version-can-i-use-with-django
33
[tox]
44
envlist =
5-
django16-{py27,py33},
6-
django17-{py27,py33,py34},
75
django18-{py27,py34,py35},
86
django19-{py27,py34,py35},
97
django110-{py27,py35},
108
django111-{py27,py35,py36},
9+
django20-{py35,py36},
1110
# run one of the tests again but with coverage
1211
coveralls-django111-py36,
1312
skipsdist = True
@@ -19,12 +18,11 @@ commands =
1918
{envpython} example_project/manage.py test django_object_actions
2019
deps =
2120
-rrequirements.txt
22-
django16: Django<1.7
23-
django17: Django<1.8
2421
django18: Django<1.9
2522
django19: Django<1.10
2623
django110: Django<1.11
2724
django111: Django<1.12
25+
django20: Django<2.1
2826

2927
[testenv:coveralls-django111-py36]
3028
commands =

0 commit comments

Comments
 (0)