Skip to content

Commit de01127

Browse files
authored
feat: Add support for Django 6.0 (#72)
* feat: Add support for Django 6.0 * fix: Indentation
1 parent 0e8bd16 commit de01127

File tree

4 files changed

+30
-11
lines changed

4 files changed

+30
-11
lines changed

CHANGELOG.rst

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
Changelog
22
=========
33

4-
Unreleased
4+
django-fsm-2 4.1.0 unreleased
55
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
66

7+
- Add support for Django 6.0
78
- Add support for Django 5.2
9+
- Add support for python 3.14
810
- Add support for python 3.13
911

1012

django_fsm/__init__.py

Lines changed: 22 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
from functools import partialmethod
99
from functools import wraps
1010

11+
from django import VERSION as DJANGO_VERSION
1112
from django.apps import apps as django_apps
1213
from django.db import models
1314
from django.db.models import Field
@@ -479,7 +480,7 @@ def __init__(self, *args, **kwargs):
479480
def state_fields(self):
480481
return filter(lambda field: isinstance(field, FSMFieldMixin), self._meta.fields)
481482

482-
def _do_update(self, base_qs, using, pk_val, values, update_fields, forced_update):
483+
def _do_update(self, base_qs, using, pk_val, values, update_fields, forced_update, returning_fields=None):
483484
# _do_update is called once for each model class in the inheritance hierarchy.
484485
# We can only filter the base_qs on state fields (can be more than one!) present in this particular model.
485486

@@ -489,14 +490,26 @@ def _do_update(self, base_qs, using, pk_val, values, update_fields, forced_updat
489490
# state filter will be used to narrow down the standard filter checking only PK
490491
state_filter = {field.attname: self.__initial_states[field.attname] for field in filter_on}
491492

492-
updated = super()._do_update(
493-
base_qs=base_qs.filter(**state_filter),
494-
using=using,
495-
pk_val=pk_val,
496-
values=values,
497-
update_fields=update_fields,
498-
forced_update=forced_update,
499-
)
493+
# Django 6.0+ added returning_fields parameter to _do_update
494+
if DJANGO_VERSION >= (6, 0):
495+
updated = super()._do_update(
496+
base_qs=base_qs.filter(**state_filter),
497+
using=using,
498+
pk_val=pk_val,
499+
values=values,
500+
update_fields=update_fields,
501+
forced_update=forced_update,
502+
returning_fields=returning_fields,
503+
)
504+
else:
505+
updated = super()._do_update(
506+
base_qs=base_qs.filter(**state_filter),
507+
using=using,
508+
pk_val=pk_val,
509+
values=values,
510+
update_fields=update_fields,
511+
forced_update=forced_update,
512+
)
500513

501514
# It may happen that nothing was updated in the original _do_update method not because of unmatching state,
502515
# but because of missing PK. This codepath is possible when saving a new model instance with *preset PK*.

pyproject.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ classifiers = [
2121
"Framework :: Django :: 5.0",
2222
"Framework :: Django :: 5.1",
2323
"Framework :: Django :: 5.2",
24+
"Framework :: Django :: 6.0",
2425
'Programming Language :: Python',
2526
'Programming Language :: Python :: 3',
2627
'Programming Language :: Python :: 3.8',
@@ -29,6 +30,7 @@ classifiers = [
2930
'Programming Language :: Python :: 3.11',
3031
'Programming Language :: Python :: 3.12',
3132
'Programming Language :: Python :: 3.13',
33+
'Programming Language :: Python :: 3.14',
3234
'Topic :: Software Development :: Libraries :: Python Modules',
3335
]
3436
packages = [{ include = "django_fsm" }]

tox.ini

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@ envlist =
44
py{310,311,312}-dj50
55
py{310,311,312}-dj51
66
py{310,311,312,313,314}-dj52
7-
# py{312,313,314}-djmain
7+
py{312,313,314}-dj60
8+
py{312,313,314}-djmain
89

910
skipsdist = True
1011

@@ -14,6 +15,7 @@ deps =
1415
dj50: Django==5.0
1516
dj51: Django==5.1
1617
dj52: Django==5.2
18+
dj60: Django>=6.0a1,<6.1
1719
djmain: https://github.com/django/django/tarball/main
1820

1921
django-guardian

0 commit comments

Comments
 (0)