Skip to content

Commit

Permalink
Upgrade code for Django 3.2
Browse files Browse the repository at this point in the history
  • Loading branch information
aleksandr-shtaub committed Jan 20, 2022
1 parent c81e2c9 commit 821297f
Show file tree
Hide file tree
Showing 7 changed files with 70 additions and 38 deletions.
38 changes: 26 additions & 12 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,32 @@ language: python

matrix:
include:
- python: 2.7
env: TOX_ENV=py27
- python: 2.7
env: TOX_ENV=py27-django18
- python: 2.7
env: TOX_ENV=py27-django111
- python: 3.6
env: TOX_ENV=py36
- python: 3.6
env: TOX_ENV=py36-django18
- python: 3.6
env: TOX_ENV=py36-djangostable
- python: 3.7
env: TOX_ENV=py37-django22
- python: 3.7
env: TOX_ENV=py37-django30
- python: 3.7
env: TOX_ENV=py37-django31
- python: 3.7
env: TOX_ENV=py37-django32
- python: 3.8
env: TOX_ENV=py38-django22
- python: 3.8
env: TOX_ENV=py38-django30
- python: 3.8
env: TOX_ENV=py38-django31
- python: 3.8
env: TOX_ENV=py38-django32
- python: 3.9
env: TOX_ENV=py39-django22
- python: 3.9
env: TOX_ENV=py39-django30
- python: 3.9
env: TOX_ENV=py39-django31
- python: 3.9
env: TOX_ENV=py39-django32
- python: 3.9
env: TOX_ENV=py39-djangostable
- env: TOX_ENV=flake8

install:
Expand Down
2 changes: 2 additions & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ Changelog
------------------

- Update code for python>=3.7
- Add support for Django 2.2-3.2
- Add support for PyYAML 6.0


0.5.0 (2018-08-30)
Expand Down
29 changes: 21 additions & 8 deletions demo/demo/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,22 +20,35 @@ class World(models.Model):


class City(models.Model):
world = models.ForeignKey(World, related_name='cities')

world = models.ForeignKey(
World,
on_delete=models.CASCADE,
related_name='cities'
)
name = models.CharField(max_length=40)


class Abode(models.Model):
city = models.ForeignKey(City, related_name='abodes')
owner = models.OneToOneField('Citizen', related_name='owned_abode',
null=True)

city = models.ForeignKey(
City,
on_delete=models.CASCADE,
related_name='abodes'
)
owner = models.OneToOneField(
'Citizen',
on_delete=models.CASCADE,
related_name='owned_abode',
null=True
)
type = models.CharField(max_length=2, choices=ABODE_TYPES)


class Citizen(models.Model):
abode = models.ForeignKey(Abode, related_name='citizens')

abode = models.ForeignKey(
Abode,
on_delete=models.CASCADE,
related_name='citizens'
)
first_name = models.CharField(max_length=20)
middle_name = models.CharField(max_length=20, blank=True, default='')
last_name = models.CharField(max_length=20)
Expand Down
4 changes: 2 additions & 2 deletions demo/urls.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
from django.conf.urls import include, url
from django.urls import include, path
from django.contrib import admin

urlpatterns = [
# Examples:
# url(r'^$', 'demo.views.home', name='home'),
# url(r'^blog/', include('blog.urls')),

url(r'^admin/', include(admin.site.urls)),
path('admin/', include(admin.site.urls)),
]
2 changes: 1 addition & 1 deletion tests/django/project/app/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class Test(models.Model):
ip_v4 = models.GenericIPAddressField(protocol='IPv4')
ip_v6 = models.GenericIPAddressField(protocol='IPv6')
integer = models.IntegerField()
null_boolean = models.NullBooleanField()
null_boolean = models.BooleanField(null=True)
positive_int = models.PositiveIntegerField()
positive_small_int = models.PositiveSmallIntegerField()
small_integer = models.SmallIntegerField()
Expand Down
29 changes: 15 additions & 14 deletions tests/django/test_command.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
def test_call_command(capsys):
import django
from django.core.management import call_command
import django
from django.core.management import call_command

def test_call_command(capsys):
call_command('populous', 'auth', 'app')

out, err = capsys.readouterr()
assert out == """items:
assert out == f"""items:
- name: Permission
table: auth_permission
fields:
Expand All @@ -24,7 +24,7 @@ def test_call_command(capsys):
name:
generator: Text
min_length: 1
max_length: 80
max_length: 150
unique: true
- name: User
table: auth_user
Expand All @@ -41,16 +41,16 @@ def test_call_command(capsys):
username:
generator: Text
min_length: 1
max_length: {username_length}
max_length: 150
unique: true
first_name:
generator: Text
min_length: 0
max_length: 30
max_length: {30 if django.VERSION < (3,1) else 150}
last_name:
generator: Text
min_length: 0
max_length: {lastname_length}
max_length: 150
email:
generator: Email
min_length: 0
Expand Down Expand Up @@ -142,11 +142,12 @@ def test_call_command(capsys):
unique: false
char_choices:
generator: Choices
choices: [foo, bar]
choices:
- foo
- bar
int_choices:
generator: Choices
choices: [1, 2]
""".format(
username_length=30 if django.VERSION < (1, 10) else 150,
lastname_length=30 if django.VERSION < (2,) else 150,
)
choices:
- 1
- 2
"""
4 changes: 3 additions & 1 deletion tox.ini
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
[tox]
envlist = py{37,38,39}-django{22,32,stable}
envlist = py{37,38,39}-django{22,30,31,32,stable}
skipsdist = True

[testenv]
passenv = ARCHFLAGS CC
deps =
pytest-cov
django22: Django~=2.2.0
django30: Django~=3.0.0
django31: Django~=3.1.0
django32: Django~=3.2.0
djangostable: Django
commands =
Expand Down

0 comments on commit 821297f

Please sign in to comment.