Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update support of Python and Django versions #532

Merged
merged 4 commits into from
Aug 18, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@ jobs:
fail-fast: false
max-parallel: 5
matrix:
python-version: ['3.6', '3.7', '3.8', '3.9', '3.10']
python-version: ['3.7', '3.8', '3.9', '3.10']

services:
postgres:
image: postgres:10
image: postgres:12
env:
POSTGRES_USER: postgres
POSTGRES_PASSWORD: postgres
Expand Down
6 changes: 6 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,9 @@ repos:
- id: flake8
args: ['--ignore=E402,E501,E731,W503']
files: ^(model_utils|tests)/

- repo: https://github.com/asottile/pyupgrade
rev: v2.37.3
hooks:
- id: pyupgrade
args: [--py37-plus]
3 changes: 3 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ Unreleased
- Add Spanish translation
- Add French translation
- Drop Django 1.7 workaround from `select_subclasses()`
- Drop support for `Django < 3.2`
- Drop support for `Python 3.6`
- Confirm support for `Django 4.1`

4.2.0 (2021-10-11)
------------------
Expand Down
2 changes: 1 addition & 1 deletion README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ django-model-utils

Django model mixins and utilities.

``django-model-utils`` supports `Django`_ 2.2+.
``django-model-utils`` supports `Django`_ 3.2+.

.. _Django: http://www.djangoproject.com/

Expand Down
4 changes: 2 additions & 2 deletions docs/setup.rst
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ modify your ``INSTALLED_APPS`` setting.
Dependencies
============

``django-model-utils`` supports `Django`_ 2.2, 3.1 and 3.2 (latest bugfix
release in each series only) on Python 3.6+.
``django-model-utils`` supports `Django`_ 3.2+ (latest bugfix
release in each series only) on Python 3.7+.

.. _Django: http://www.djangoproject.com/
6 changes: 3 additions & 3 deletions model_utils/managers.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ def _get_ancestors_path(self, model, levels=None):
"""
if not issubclass(model, self.model):
raise ValueError(
"{!r} is not a subclass of {!r}".format(model, self.model))
f"{model!r} is not a subclass of {self.model!r}")

ancestry = []
# should be a OneToOneField or None
Expand Down Expand Up @@ -308,7 +308,7 @@ def get_quoted_query(self, query):

# Put additional quotes around string.
params = [
'\'{}\''.format(p)
f'\'{p}\''
if isinstance(p, str) else p
for p in params
]
Expand Down Expand Up @@ -338,7 +338,7 @@ def join(self, qs=None):
if getattr(fk, 'related_model', None) == self.model
]
fk = fk[0] if fk else None
model_set = '{}_set'.format(self.model.__name__.lower())
model_set = f'{self.model.__name__.lower()}_set'
key = fk or getattr(qs.model, model_set, None)

if not key:
Expand Down
9 changes: 4 additions & 5 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ def long_desc(root_path):
for filename in FILES:
filepath = os.path.realpath(os.path.join(root_path, filename))
if os.path.isfile(filepath):
with open(filepath, mode='r') as f:
with open(filepath) as f:
yield f.read()


Expand All @@ -29,7 +29,8 @@ def long_desc(root_path):
maintainer='JazzBand',
url='https://github.com/jazzband/django-model-utils',
packages=find_packages(exclude=['tests*']),
install_requires=['Django>=2.2'],
python_requires=">=3.7",
install_requires=['Django>=3.2'],
classifiers=[
'Development Status :: 5 - Production/Stable',
'Environment :: Web Environment',
Expand All @@ -38,16 +39,14 @@ def long_desc(root_path):
'Operating System :: OS Independent',
'Programming Language :: Python',
'Programming Language :: Python :: 3',
'Programming Language :: Python :: 3.6',
'Programming Language :: Python :: 3.7',
'Programming Language :: Python :: 3.8',
'Programming Language :: Python :: 3.9',
'Programming Language :: Python :: 3.10',
'Framework :: Django',
'Framework :: Django :: 2.2',
'Framework :: Django :: 3.1',
'Framework :: Django :: 3.2',
'Framework :: Django :: 4.0',
'Framework :: Django :: 4.1',
],
zip_safe=False,
package_data={
Expand Down
11 changes: 3 additions & 8 deletions tests/models.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import django
from django.db import models
from django.db.models import Manager
from django.db.models.query_utils import DeferredAttribute
Expand Down Expand Up @@ -387,13 +386,9 @@ def __get__(self, obj, cls=None):
return self
if self.name in obj.get_deferred_fields():
# This queries the database, and sets the value on the instance.
if django.VERSION < (3, 0):
DeferredAttribute(field_name=self.name).__get__(obj, cls)
else:
# Since Django 3.0, DeferredAttribute wants a field argument.
fields_map = {f.name: f for f in cls._meta.fields}
field = fields_map[self.name]
DeferredAttribute(field=field).__get__(obj, cls)
fields_map = {f.name: f for f in cls._meta.fields}
field = fields_map[self.name]
DeferredAttribute(field=field).__get__(obj, cls)
return str(obj.__dict__[self.name])

def __set__(self, obj, value):
Expand Down
2 changes: 1 addition & 1 deletion tests/test_managers/test_join_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
class JoinManagerTest(TestCase):
def setUp(self):
for i in range(20):
BoxJoinModel.objects.create(name='name_{i}'.format(i=i))
BoxJoinModel.objects.create(name=f'name_{i}')

JoinItemForeignKey.objects.create(
weight=10, belonging=BoxJoinModel.objects.get(name='name_1')
Expand Down
9 changes: 3 additions & 6 deletions tox.ini
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
[tox]
envlist =
py{36,37,38,39}-dj{22,31}
py{36,37,38,39,310}-dj32
py{38,39,310}-dj{40,main}
py{37,38,39,310}-dj32
py{38,39,310}-dj{40,41,main}
flake8
isort

[gh-actions]
python =
3.6: py36
3.7: py37
3.8: py38, flake8, isort
3.9: py39
Expand All @@ -18,10 +16,9 @@ python =
deps =
freezegun==0.3.12
-rrequirements-test.txt
dj22: Django==2.2.*
dj31: Django==3.1.*
dj32: Django==3.2.*
dj40: Django==4.0.*
dj41: Django==4.1.*
djmain: https://github.com/django/django/archive/main.tar.gz
ignore_outcome =
djmain: True
Expand Down