django-modelcluster 6.2.1__tar.gz → 6.4__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {django-modelcluster-6.2.1 → django-modelcluster-6.4}/CHANGELOG.txt +17 -0
- {django-modelcluster-6.2.1/django_modelcluster.egg-info → django-modelcluster-6.4}/PKG-INFO +3 -3
- {django-modelcluster-6.2.1 → django-modelcluster-6.4/django_modelcluster.egg-info}/PKG-INFO +3 -3
- {django-modelcluster-6.2.1 → django-modelcluster-6.4}/django_modelcluster.egg-info/SOURCES.txt +1 -0
- {django-modelcluster-6.2.1 → django-modelcluster-6.4}/django_modelcluster.egg-info/requires.txt +1 -2
- django-modelcluster-6.4/modelcluster/datetime_utils.py +119 -0
- {django-modelcluster-6.2.1 → django-modelcluster-6.4}/modelcluster/forms.py +3 -1
- {django-modelcluster-6.2.1 → django-modelcluster-6.4}/modelcluster/queryset.py +171 -161
- {django-modelcluster-6.2.1 → django-modelcluster-6.4}/modelcluster/utils.py +91 -10
- {django-modelcluster-6.2.1 → django-modelcluster-6.4}/setup.py +4 -5
- {django-modelcluster-6.2.1 → django-modelcluster-6.4}/LICENSE +0 -0
- {django-modelcluster-6.2.1 → django-modelcluster-6.4}/MANIFEST.in +0 -0
- {django-modelcluster-6.2.1 → django-modelcluster-6.4}/README.rst +0 -0
- {django-modelcluster-6.2.1 → django-modelcluster-6.4}/django_modelcluster.egg-info/dependency_links.txt +0 -0
- {django-modelcluster-6.2.1 → django-modelcluster-6.4}/django_modelcluster.egg-info/top_level.txt +0 -0
- {django-modelcluster-6.2.1 → django-modelcluster-6.4}/modelcluster/__init__.py +0 -0
- {django-modelcluster-6.2.1 → django-modelcluster-6.4}/modelcluster/contrib/__init__.py +0 -0
- {django-modelcluster-6.2.1 → django-modelcluster-6.4}/modelcluster/contrib/taggit.py +0 -0
- {django-modelcluster-6.2.1 → django-modelcluster-6.4}/modelcluster/fields.py +0 -0
- {django-modelcluster-6.2.1 → django-modelcluster-6.4}/modelcluster/models.py +0 -0
- {django-modelcluster-6.2.1 → django-modelcluster-6.4}/modelcluster/tags.py +0 -0
- {django-modelcluster-6.2.1 → django-modelcluster-6.4}/setup.cfg +0 -0
|
@@ -1,6 +1,23 @@
|
|
|
1
1
|
Changelog
|
|
2
2
|
=========
|
|
3
3
|
|
|
4
|
+
6.4 (18.12.2024)
|
|
5
|
+
~~~~~~~~~~~~~~~~
|
|
6
|
+
* Add `UniqueConstraint` support for uniqueness validation (Sage Abdullah)
|
|
7
|
+
* Remove `pytz` dependency (Sage Abdullah)
|
|
8
|
+
* Added Django 5.1 and Python 3.13 support
|
|
9
|
+
* Removed Django 3.2 and Python 3.8 support
|
|
10
|
+
|
|
11
|
+
6.3 (26.02.2024)
|
|
12
|
+
~~~~~~~~~~~~~~~~
|
|
13
|
+
* Support filtering with Q objects (Shohan Dutta Roy)
|
|
14
|
+
* Support random ordering with `.order_by("?")` (Shohan Dutta Roy)
|
|
15
|
+
* Support `distinct()` on querysets (Shohan Dutta Roy)
|
|
16
|
+
* Support `iso_weekday` and `iso_year` field lookups (Andy Babic)
|
|
17
|
+
* Support datetime transform expressions on `values` and `values_list` (Andy Babic)
|
|
18
|
+
* Fix: Correctly handle filtering on fields on related models when those fields have names that match a lookup type (Andy Babic)
|
|
19
|
+
* Fix: Correctly handle null foreign keys when traversing related fields (Andy Babic)
|
|
20
|
+
|
|
4
21
|
6.2.1 (04.01.2024)
|
|
5
22
|
~~~~~~~~~~~~~~~~~~
|
|
6
23
|
* Fix: Prevent failure on pre-3.1.0 versions of django-taggit without `_remove_prefetched_objects`
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
2
|
Name: django-modelcluster
|
|
3
|
-
Version: 6.
|
|
3
|
+
Version: 6.4
|
|
4
4
|
Summary: Django extension to allow working with 'clusters' of models as a single unit, independently of the database
|
|
5
5
|
Home-page: https://github.com/wagtail/django-modelcluster
|
|
6
6
|
Author: Matthew Westcott
|
|
@@ -13,14 +13,14 @@ Classifier: License :: OSI Approved :: BSD License
|
|
|
13
13
|
Classifier: Operating System :: OS Independent
|
|
14
14
|
Classifier: Programming Language :: Python
|
|
15
15
|
Classifier: Programming Language :: Python :: 3
|
|
16
|
-
Classifier: Programming Language :: Python :: 3.8
|
|
17
16
|
Classifier: Programming Language :: Python :: 3.9
|
|
18
17
|
Classifier: Programming Language :: Python :: 3.10
|
|
19
18
|
Classifier: Programming Language :: Python :: 3.11
|
|
20
19
|
Classifier: Programming Language :: Python :: 3.12
|
|
20
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
21
21
|
Classifier: Programming Language :: Python :: 3 :: Only
|
|
22
22
|
Classifier: Framework :: Django
|
|
23
|
-
Requires-Python: >=3.
|
|
23
|
+
Requires-Python: >=3.9
|
|
24
24
|
Provides-Extra: taggit
|
|
25
25
|
License-File: LICENSE
|
|
26
26
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
2
|
Name: django-modelcluster
|
|
3
|
-
Version: 6.
|
|
3
|
+
Version: 6.4
|
|
4
4
|
Summary: Django extension to allow working with 'clusters' of models as a single unit, independently of the database
|
|
5
5
|
Home-page: https://github.com/wagtail/django-modelcluster
|
|
6
6
|
Author: Matthew Westcott
|
|
@@ -13,14 +13,14 @@ Classifier: License :: OSI Approved :: BSD License
|
|
|
13
13
|
Classifier: Operating System :: OS Independent
|
|
14
14
|
Classifier: Programming Language :: Python
|
|
15
15
|
Classifier: Programming Language :: Python :: 3
|
|
16
|
-
Classifier: Programming Language :: Python :: 3.8
|
|
17
16
|
Classifier: Programming Language :: Python :: 3.9
|
|
18
17
|
Classifier: Programming Language :: Python :: 3.10
|
|
19
18
|
Classifier: Programming Language :: Python :: 3.11
|
|
20
19
|
Classifier: Programming Language :: Python :: 3.12
|
|
20
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
21
21
|
Classifier: Programming Language :: Python :: 3 :: Only
|
|
22
22
|
Classifier: Framework :: Django
|
|
23
|
-
Requires-Python: >=3.
|
|
23
|
+
Requires-Python: >=3.9
|
|
24
24
|
Provides-Extra: taggit
|
|
25
25
|
License-File: LICENSE
|
|
26
26
|
|
{django-modelcluster-6.2.1 → django-modelcluster-6.4}/django_modelcluster.egg-info/SOURCES.txt
RENAMED
|
@@ -10,6 +10,7 @@ django_modelcluster.egg-info/dependency_links.txt
|
|
|
10
10
|
django_modelcluster.egg-info/requires.txt
|
|
11
11
|
django_modelcluster.egg-info/top_level.txt
|
|
12
12
|
modelcluster/__init__.py
|
|
13
|
+
modelcluster/datetime_utils.py
|
|
13
14
|
modelcluster/fields.py
|
|
14
15
|
modelcluster/forms.py
|
|
15
16
|
modelcluster/models.py
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
import datetime
|
|
2
|
+
|
|
3
|
+
from django import forms
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
TIMEFIELD_TRANSFORM_EXPRESSIONS = {"hour", "minute", "second"}
|
|
7
|
+
DATEFIELD_TRANSFORM_EXPRESSIONS = {
|
|
8
|
+
"year",
|
|
9
|
+
"iso_year",
|
|
10
|
+
"month",
|
|
11
|
+
"day",
|
|
12
|
+
"week",
|
|
13
|
+
"week_day",
|
|
14
|
+
"iso_week_day",
|
|
15
|
+
"quarter",
|
|
16
|
+
}
|
|
17
|
+
DATETIMEFIELD_TRANSFORM_EXPRESSIONS = (
|
|
18
|
+
{"date", "time"}
|
|
19
|
+
| TIMEFIELD_TRANSFORM_EXPRESSIONS
|
|
20
|
+
| DATEFIELD_TRANSFORM_EXPRESSIONS
|
|
21
|
+
)
|
|
22
|
+
TRANSFORM_FIELD_TYPES = {
|
|
23
|
+
"year": forms.IntegerField,
|
|
24
|
+
"iso_year": forms.IntegerField,
|
|
25
|
+
"month": forms.IntegerField,
|
|
26
|
+
"hour": forms.IntegerField,
|
|
27
|
+
"minute": forms.IntegerField,
|
|
28
|
+
"second": forms.IntegerField,
|
|
29
|
+
"day": forms.IntegerField,
|
|
30
|
+
"week": forms.IntegerField,
|
|
31
|
+
"week_day": forms.IntegerField,
|
|
32
|
+
"iso_week_day": forms.IntegerField,
|
|
33
|
+
"quarter": forms.IntegerField,
|
|
34
|
+
"date": forms.DateField,
|
|
35
|
+
"time": forms.TimeField,
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
def derive_from_value(value, expr):
|
|
40
|
+
if isinstance(value, datetime.datetime):
|
|
41
|
+
return derive_from_datetime(value, expr)
|
|
42
|
+
if isinstance(value, datetime.date):
|
|
43
|
+
return derive_from_date(value, expr)
|
|
44
|
+
if isinstance(value, datetime.time):
|
|
45
|
+
return derive_from_time(value, expr)
|
|
46
|
+
return None
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
def derive_from_time(value, expr):
|
|
50
|
+
"""
|
|
51
|
+
Mimics the behaviour of the ``hour``, ``minute`` and ``second`` lookup
|
|
52
|
+
expressions that Django querysets support for ``TimeField`` and
|
|
53
|
+
``DateTimeField``, by extracting the relevant value from an in-memory
|
|
54
|
+
``time`` or ``datetime`` value.
|
|
55
|
+
"""
|
|
56
|
+
if expr == "hour":
|
|
57
|
+
return value.hour
|
|
58
|
+
if expr == "minute":
|
|
59
|
+
return value.minute
|
|
60
|
+
if expr == "second":
|
|
61
|
+
return value.second
|
|
62
|
+
raise ValueError(
|
|
63
|
+
"Expression '{expression}' is not supported for {value}".format(
|
|
64
|
+
expression=expr, value=repr(value)
|
|
65
|
+
)
|
|
66
|
+
)
|
|
67
|
+
|
|
68
|
+
|
|
69
|
+
def derive_from_date(value, expr):
|
|
70
|
+
"""
|
|
71
|
+
Mimics the behaviour of the ``year``, ``iso_year`` ``month``, ``day``,
|
|
72
|
+
``week``, ``week_day``, ``iso_week_day`` and ``quarter`` lookup
|
|
73
|
+
expressions that Django querysets support for ``DateField`` and
|
|
74
|
+
``DateTimeField`` columns, by extracting the relevant value from an
|
|
75
|
+
in-memory ``date`` or ``datetime`` value.
|
|
76
|
+
"""
|
|
77
|
+
if expr == "year":
|
|
78
|
+
return value.year
|
|
79
|
+
if expr == "iso_year":
|
|
80
|
+
return value.isocalendar()[0]
|
|
81
|
+
if expr == "month":
|
|
82
|
+
return value.month
|
|
83
|
+
if expr == "day":
|
|
84
|
+
return value.day
|
|
85
|
+
if expr == "week":
|
|
86
|
+
return value.isocalendar()[1]
|
|
87
|
+
if expr == "week_day":
|
|
88
|
+
v = value.isoweekday()
|
|
89
|
+
return 1 if v == 7 else v + 1
|
|
90
|
+
if expr == "iso_week_day":
|
|
91
|
+
return value.isoweekday()
|
|
92
|
+
if expr == "quarter":
|
|
93
|
+
return (value.month - 1) // 3 + 1
|
|
94
|
+
raise ValueError(
|
|
95
|
+
"Expression '{expression}' is not supported for {value}".format(
|
|
96
|
+
expression=expr, value=repr(value)
|
|
97
|
+
)
|
|
98
|
+
)
|
|
99
|
+
|
|
100
|
+
|
|
101
|
+
def derive_from_datetime(value, expr):
|
|
102
|
+
"""
|
|
103
|
+
Mimics the behaviour of the ``date``, ``time`` and other lookup
|
|
104
|
+
expressions that Django querysets support for ``DateTimeField`` columns,
|
|
105
|
+
by extracting the relevant value from an in-memory ``datetime`` value.
|
|
106
|
+
"""
|
|
107
|
+
if expr == "date":
|
|
108
|
+
return value.date()
|
|
109
|
+
if expr == "time":
|
|
110
|
+
return value.time()
|
|
111
|
+
if expr in TIMEFIELD_TRANSFORM_EXPRESSIONS:
|
|
112
|
+
return derive_from_time(value, expr)
|
|
113
|
+
if expr in DATEFIELD_TRANSFORM_EXPRESSIONS:
|
|
114
|
+
return derive_from_date(value, expr)
|
|
115
|
+
raise ValueError(
|
|
116
|
+
"Expression '{expression}' is not supported for {value}".format(
|
|
117
|
+
expression=expr, value=repr(value)
|
|
118
|
+
)
|
|
119
|
+
)
|
|
@@ -134,7 +134,9 @@ class BaseChildFormSet(BaseTransientModelFormSet):
|
|
|
134
134
|
forms_to_delete = self.deleted_forms
|
|
135
135
|
valid_forms = [form for form in self.forms if form.is_valid() and form not in forms_to_delete]
|
|
136
136
|
for form in valid_forms:
|
|
137
|
-
unique_checks, date_checks = form.instance._get_unique_checks(
|
|
137
|
+
unique_checks, date_checks = form.instance._get_unique_checks(
|
|
138
|
+
include_meta_constraints=True
|
|
139
|
+
)
|
|
138
140
|
all_unique_checks.update(unique_checks)
|
|
139
141
|
all_date_checks.update(date_checks)
|
|
140
142
|
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
from __future__ import unicode_literals
|
|
2
2
|
|
|
3
|
-
import datetime
|
|
4
3
|
import re
|
|
5
4
|
|
|
6
|
-
from django.
|
|
5
|
+
from django.core.exceptions import FieldDoesNotExist
|
|
6
|
+
from django.db.models import Model, Q, prefetch_related_objects
|
|
7
7
|
|
|
8
|
-
from modelcluster.utils import extract_field_value, get_model_field, sort_by_fields
|
|
8
|
+
from modelcluster.utils import NullRelationshipValueEncountered, extract_field_value, get_model_field, sort_by_fields
|
|
9
9
|
|
|
10
10
|
|
|
11
11
|
# Constructor for test functions that determine whether an object passes some boolean condition
|
|
@@ -13,23 +13,44 @@ def test_exact(model, attribute_name, value):
|
|
|
13
13
|
if isinstance(value, Model):
|
|
14
14
|
if value.pk is None:
|
|
15
15
|
# comparing against an unsaved model, so objects need to match by reference
|
|
16
|
-
|
|
16
|
+
def _test(obj):
|
|
17
|
+
try:
|
|
18
|
+
other_value = extract_field_value(obj, attribute_name)
|
|
19
|
+
except NullRelationshipValueEncountered:
|
|
20
|
+
return False
|
|
21
|
+
return other_value is value
|
|
22
|
+
|
|
23
|
+
return _test
|
|
24
|
+
|
|
17
25
|
else:
|
|
18
26
|
# comparing against a saved model; objects need to match by type and ID.
|
|
19
27
|
# Additionally, where model inheritance is involved, we need to treat it as a
|
|
20
28
|
# positive match if one is a subclass of the other
|
|
21
29
|
def _test(obj):
|
|
22
|
-
|
|
23
|
-
|
|
30
|
+
try:
|
|
31
|
+
other_value = extract_field_value(obj, attribute_name)
|
|
32
|
+
except NullRelationshipValueEncountered:
|
|
24
33
|
return False
|
|
25
|
-
return value.pk == other_value.pk
|
|
34
|
+
return value.pk == other_value.pk and (
|
|
35
|
+
isinstance(value, other_value.__class__)
|
|
36
|
+
or isinstance(other_value, value.__class__)
|
|
37
|
+
)
|
|
38
|
+
|
|
26
39
|
return _test
|
|
27
40
|
else:
|
|
28
41
|
field = get_model_field(model, attribute_name)
|
|
29
42
|
# convert value to the correct python type for this field
|
|
30
43
|
typed_value = field.to_python(value)
|
|
44
|
+
|
|
31
45
|
# just a plain Python value = do a normal equality check
|
|
32
|
-
|
|
46
|
+
def _test(obj):
|
|
47
|
+
try:
|
|
48
|
+
other_value = extract_field_value(obj, attribute_name)
|
|
49
|
+
except NullRelationshipValueEncountered:
|
|
50
|
+
return False
|
|
51
|
+
return other_value == typed_value
|
|
52
|
+
|
|
53
|
+
return _test
|
|
33
54
|
|
|
34
55
|
|
|
35
56
|
def test_iexact(model, attribute_name, match_value):
|
|
@@ -37,15 +58,24 @@ def test_iexact(model, attribute_name, match_value):
|
|
|
37
58
|
match_value = field.to_python(match_value)
|
|
38
59
|
|
|
39
60
|
if match_value is None:
|
|
40
|
-
|
|
61
|
+
|
|
62
|
+
def _test(obj):
|
|
63
|
+
try:
|
|
64
|
+
val = extract_field_value(obj, attribute_name)
|
|
65
|
+
except NullRelationshipValueEncountered:
|
|
66
|
+
return False
|
|
67
|
+
return val is None
|
|
41
68
|
else:
|
|
42
69
|
match_value = match_value.upper()
|
|
43
70
|
|
|
44
71
|
def _test(obj):
|
|
45
|
-
|
|
72
|
+
try:
|
|
73
|
+
val = extract_field_value(obj, attribute_name)
|
|
74
|
+
except NullRelationshipValueEncountered:
|
|
75
|
+
return False
|
|
46
76
|
return val is not None and val.upper() == match_value
|
|
47
77
|
|
|
48
|
-
|
|
78
|
+
return _test
|
|
49
79
|
|
|
50
80
|
|
|
51
81
|
def test_contains(model, attribute_name, value):
|
|
@@ -53,7 +83,10 @@ def test_contains(model, attribute_name, value):
|
|
|
53
83
|
match_value = field.to_python(value)
|
|
54
84
|
|
|
55
85
|
def _test(obj):
|
|
56
|
-
|
|
86
|
+
try:
|
|
87
|
+
val = extract_field_value(obj, attribute_name)
|
|
88
|
+
except NullRelationshipValueEncountered:
|
|
89
|
+
return False
|
|
57
90
|
return val is not None and match_value in val
|
|
58
91
|
|
|
59
92
|
return _test
|
|
@@ -64,7 +97,10 @@ def test_icontains(model, attribute_name, value):
|
|
|
64
97
|
match_value = field.to_python(value).upper()
|
|
65
98
|
|
|
66
99
|
def _test(obj):
|
|
67
|
-
|
|
100
|
+
try:
|
|
101
|
+
val = extract_field_value(obj, attribute_name)
|
|
102
|
+
except NullRelationshipValueEncountered:
|
|
103
|
+
return False
|
|
68
104
|
return val is not None and match_value in val.upper()
|
|
69
105
|
|
|
70
106
|
return _test
|
|
@@ -75,7 +111,10 @@ def test_lt(model, attribute_name, value):
|
|
|
75
111
|
match_value = field.to_python(value)
|
|
76
112
|
|
|
77
113
|
def _test(obj):
|
|
78
|
-
|
|
114
|
+
try:
|
|
115
|
+
val = extract_field_value(obj, attribute_name)
|
|
116
|
+
except NullRelationshipValueEncountered:
|
|
117
|
+
return False
|
|
79
118
|
return val is not None and val < match_value
|
|
80
119
|
|
|
81
120
|
return _test
|
|
@@ -86,7 +125,10 @@ def test_lte(model, attribute_name, value):
|
|
|
86
125
|
match_value = field.to_python(value)
|
|
87
126
|
|
|
88
127
|
def _test(obj):
|
|
89
|
-
|
|
128
|
+
try:
|
|
129
|
+
val = extract_field_value(obj, attribute_name)
|
|
130
|
+
except NullRelationshipValueEncountered:
|
|
131
|
+
return False
|
|
90
132
|
return val is not None and val <= match_value
|
|
91
133
|
|
|
92
134
|
return _test
|
|
@@ -97,7 +139,10 @@ def test_gt(model, attribute_name, value):
|
|
|
97
139
|
match_value = field.to_python(value)
|
|
98
140
|
|
|
99
141
|
def _test(obj):
|
|
100
|
-
|
|
142
|
+
try:
|
|
143
|
+
val = extract_field_value(obj, attribute_name)
|
|
144
|
+
except NullRelationshipValueEncountered:
|
|
145
|
+
return False
|
|
101
146
|
return val is not None and val > match_value
|
|
102
147
|
|
|
103
148
|
return _test
|
|
@@ -108,7 +153,10 @@ def test_gte(model, attribute_name, value):
|
|
|
108
153
|
match_value = field.to_python(value)
|
|
109
154
|
|
|
110
155
|
def _test(obj):
|
|
111
|
-
|
|
156
|
+
try:
|
|
157
|
+
val = extract_field_value(obj, attribute_name)
|
|
158
|
+
except NullRelationshipValueEncountered:
|
|
159
|
+
return False
|
|
112
160
|
return val is not None and val >= match_value
|
|
113
161
|
|
|
114
162
|
return _test
|
|
@@ -117,7 +165,15 @@ def test_gte(model, attribute_name, value):
|
|
|
117
165
|
def test_in(model, attribute_name, value_list):
|
|
118
166
|
field = get_model_field(model, attribute_name)
|
|
119
167
|
match_values = set(field.to_python(val) for val in value_list)
|
|
120
|
-
|
|
168
|
+
|
|
169
|
+
def _test(obj):
|
|
170
|
+
try:
|
|
171
|
+
val = extract_field_value(obj, attribute_name)
|
|
172
|
+
except NullRelationshipValueEncountered:
|
|
173
|
+
return False
|
|
174
|
+
return val in match_values
|
|
175
|
+
|
|
176
|
+
return _test
|
|
121
177
|
|
|
122
178
|
|
|
123
179
|
def test_startswith(model, attribute_name, value):
|
|
@@ -125,7 +181,10 @@ def test_startswith(model, attribute_name, value):
|
|
|
125
181
|
match_value = field.to_python(value)
|
|
126
182
|
|
|
127
183
|
def _test(obj):
|
|
128
|
-
|
|
184
|
+
try:
|
|
185
|
+
val = extract_field_value(obj, attribute_name)
|
|
186
|
+
except NullRelationshipValueEncountered:
|
|
187
|
+
return False
|
|
129
188
|
return val is not None and val.startswith(match_value)
|
|
130
189
|
|
|
131
190
|
return _test
|
|
@@ -136,7 +195,10 @@ def test_istartswith(model, attribute_name, value):
|
|
|
136
195
|
match_value = field.to_python(value).upper()
|
|
137
196
|
|
|
138
197
|
def _test(obj):
|
|
139
|
-
|
|
198
|
+
try:
|
|
199
|
+
val = extract_field_value(obj, attribute_name)
|
|
200
|
+
except NullRelationshipValueEncountered:
|
|
201
|
+
return False
|
|
140
202
|
return val is not None and val.upper().startswith(match_value)
|
|
141
203
|
|
|
142
204
|
return _test
|
|
@@ -147,7 +209,10 @@ def test_endswith(model, attribute_name, value):
|
|
|
147
209
|
match_value = field.to_python(value)
|
|
148
210
|
|
|
149
211
|
def _test(obj):
|
|
150
|
-
|
|
212
|
+
try:
|
|
213
|
+
val = extract_field_value(obj, attribute_name)
|
|
214
|
+
except NullRelationshipValueEncountered:
|
|
215
|
+
return False
|
|
151
216
|
return val is not None and val.endswith(match_value)
|
|
152
217
|
|
|
153
218
|
return _test
|
|
@@ -158,7 +223,10 @@ def test_iendswith(model, attribute_name, value):
|
|
|
158
223
|
match_value = field.to_python(value).upper()
|
|
159
224
|
|
|
160
225
|
def _test(obj):
|
|
161
|
-
|
|
226
|
+
try:
|
|
227
|
+
val = extract_field_value(obj, attribute_name)
|
|
228
|
+
except NullRelationshipValueEncountered:
|
|
229
|
+
return False
|
|
162
230
|
return val is not None and val.upper().endswith(match_value)
|
|
163
231
|
|
|
164
232
|
return _test
|
|
@@ -170,136 +238,37 @@ def test_range(model, attribute_name, range_val):
|
|
|
170
238
|
end_val = field.to_python(range_val[1])
|
|
171
239
|
|
|
172
240
|
def _test(obj):
|
|
173
|
-
|
|
241
|
+
try:
|
|
242
|
+
val = extract_field_value(obj, attribute_name)
|
|
243
|
+
except NullRelationshipValueEncountered:
|
|
244
|
+
return False
|
|
174
245
|
return (val is not None and val >= start_val and val <= end_val)
|
|
175
246
|
|
|
176
247
|
return _test
|
|
177
248
|
|
|
178
249
|
|
|
179
|
-
def
|
|
180
|
-
def _test(obj):
|
|
181
|
-
val = extract_field_value(obj, attribute_name)
|
|
182
|
-
if isinstance(val, datetime.datetime):
|
|
183
|
-
return val.date() == match_value
|
|
184
|
-
else:
|
|
185
|
-
return val == match_value
|
|
186
|
-
|
|
187
|
-
return _test
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
def test_year(model, attribute_name, match_value):
|
|
191
|
-
match_value = int(match_value)
|
|
192
|
-
|
|
193
|
-
def _test(obj):
|
|
194
|
-
val = extract_field_value(obj, attribute_name)
|
|
195
|
-
return val is not None and val.year == match_value
|
|
196
|
-
|
|
197
|
-
return _test
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
def test_month(model, attribute_name, match_value):
|
|
201
|
-
match_value = int(match_value)
|
|
202
|
-
|
|
203
|
-
def _test(obj):
|
|
204
|
-
val = extract_field_value(obj, attribute_name)
|
|
205
|
-
return val is not None and val.month == match_value
|
|
206
|
-
|
|
207
|
-
return _test
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
def test_day(model, attribute_name, match_value):
|
|
211
|
-
match_value = int(match_value)
|
|
212
|
-
|
|
213
|
-
def _test(obj):
|
|
214
|
-
val = extract_field_value(obj, attribute_name)
|
|
215
|
-
return val is not None and val.day == match_value
|
|
216
|
-
|
|
217
|
-
return _test
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
def test_week(model, attribute_name, match_value):
|
|
221
|
-
match_value = int(match_value)
|
|
222
|
-
|
|
223
|
-
def _test(obj):
|
|
224
|
-
val = extract_field_value(obj, attribute_name)
|
|
225
|
-
return val is not None and val.isocalendar()[1] == match_value
|
|
226
|
-
|
|
227
|
-
return _test
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
def test_week_day(model, attribute_name, match_value):
|
|
231
|
-
match_value = int(match_value)
|
|
232
|
-
|
|
233
|
-
def _test(obj):
|
|
234
|
-
val = extract_field_value(obj, attribute_name)
|
|
235
|
-
return val is not None and val.isoweekday() % 7 + 1 == match_value
|
|
236
|
-
|
|
237
|
-
return _test
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
def test_quarter(model, attribute_name, match_value):
|
|
241
|
-
match_value = int(match_value)
|
|
242
|
-
|
|
243
|
-
def _test(obj):
|
|
244
|
-
val = extract_field_value(obj, attribute_name)
|
|
245
|
-
return val is not None and int((val.month - 1) / 3) + 1 == match_value
|
|
246
|
-
|
|
247
|
-
return _test
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
def test_time(model, attribute_name, match_value):
|
|
250
|
+
def test_isnull(model, attribute_name, sense):
|
|
251
251
|
def _test(obj):
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
252
|
+
try:
|
|
253
|
+
val = extract_field_value(obj, attribute_name)
|
|
254
|
+
except NullRelationshipValueEncountered:
|
|
255
|
+
return False
|
|
256
|
+
if sense:
|
|
257
|
+
return val is None
|
|
255
258
|
else:
|
|
256
|
-
return val
|
|
259
|
+
return val is not None
|
|
257
260
|
|
|
258
261
|
return _test
|
|
259
262
|
|
|
260
263
|
|
|
261
|
-
def test_hour(model, attribute_name, match_value):
|
|
262
|
-
match_value = int(match_value)
|
|
263
|
-
|
|
264
|
-
def _test(obj):
|
|
265
|
-
val = extract_field_value(obj, attribute_name)
|
|
266
|
-
return val is not None and val.hour == match_value
|
|
267
|
-
|
|
268
|
-
return _test
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
def test_minute(model, attribute_name, match_value):
|
|
272
|
-
match_value = int(match_value)
|
|
273
|
-
|
|
274
|
-
def _test(obj):
|
|
275
|
-
val = extract_field_value(obj, attribute_name)
|
|
276
|
-
return val is not None and val.minute == match_value
|
|
277
|
-
|
|
278
|
-
return _test
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
def test_second(model, attribute_name, match_value):
|
|
282
|
-
match_value = int(match_value)
|
|
283
|
-
|
|
284
|
-
def _test(obj):
|
|
285
|
-
val = extract_field_value(obj, attribute_name)
|
|
286
|
-
return val is not None and val.second == match_value
|
|
287
|
-
|
|
288
|
-
return _test
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
def test_isnull(model, attribute_name, sense):
|
|
292
|
-
if sense:
|
|
293
|
-
return lambda obj: extract_field_value(obj, attribute_name) is None
|
|
294
|
-
else:
|
|
295
|
-
return lambda obj: extract_field_value(obj, attribute_name) is not None
|
|
296
|
-
|
|
297
|
-
|
|
298
264
|
def test_regex(model, attribute_name, regex_string):
|
|
299
265
|
regex = re.compile(regex_string)
|
|
300
266
|
|
|
301
267
|
def _test(obj):
|
|
302
|
-
|
|
268
|
+
try:
|
|
269
|
+
val = extract_field_value(obj, attribute_name)
|
|
270
|
+
except NullRelationshipValueEncountered:
|
|
271
|
+
return False
|
|
303
272
|
return val is not None and regex.search(val)
|
|
304
273
|
|
|
305
274
|
return _test
|
|
@@ -309,7 +278,10 @@ def test_iregex(model, attribute_name, regex_string):
|
|
|
309
278
|
regex = re.compile(regex_string, re.I)
|
|
310
279
|
|
|
311
280
|
def _test(obj):
|
|
312
|
-
|
|
281
|
+
try:
|
|
282
|
+
val = extract_field_value(obj, attribute_name)
|
|
283
|
+
except NullRelationshipValueEncountered:
|
|
284
|
+
return False
|
|
313
285
|
return val is not None and regex.search(val)
|
|
314
286
|
|
|
315
287
|
return _test
|
|
@@ -330,17 +302,6 @@ FILTER_EXPRESSION_TOKENS = {
|
|
|
330
302
|
'endswith': test_endswith,
|
|
331
303
|
'iendswith': test_iendswith,
|
|
332
304
|
'range': test_range,
|
|
333
|
-
'date': test_date,
|
|
334
|
-
'year': test_year,
|
|
335
|
-
'month': test_month,
|
|
336
|
-
'day': test_day,
|
|
337
|
-
'week': test_week,
|
|
338
|
-
'week_day': test_week_day,
|
|
339
|
-
'quarter': test_quarter,
|
|
340
|
-
'time': test_time,
|
|
341
|
-
'hour': test_hour,
|
|
342
|
-
'minute': test_minute,
|
|
343
|
-
'second': test_second,
|
|
344
305
|
'isnull': test_isnull,
|
|
345
306
|
'regex': test_regex,
|
|
346
307
|
'iregex': test_iregex,
|
|
@@ -350,8 +311,15 @@ FILTER_EXPRESSION_TOKENS = {
|
|
|
350
311
|
def _build_test_function_from_filter(model, key_clauses, val):
|
|
351
312
|
# Translate a filter kwarg rule (e.g. foo__bar__exact=123) into a function which can
|
|
352
313
|
# take a model instance and return a boolean indicating whether it passes the rule
|
|
353
|
-
|
|
354
|
-
|
|
314
|
+
try:
|
|
315
|
+
get_model_field(model, "__".join(key_clauses))
|
|
316
|
+
except FieldDoesNotExist:
|
|
317
|
+
# it is safe to assume the last clause indicates the type of test
|
|
318
|
+
field_match_found = False
|
|
319
|
+
else:
|
|
320
|
+
field_match_found = True
|
|
321
|
+
|
|
322
|
+
if not field_match_found and key_clauses[-1] in FILTER_EXPRESSION_TOKENS:
|
|
355
323
|
constructor = FILTER_EXPRESSION_TOKENS[key_clauses.pop()]
|
|
356
324
|
else:
|
|
357
325
|
constructor = test_exact
|
|
@@ -376,7 +344,7 @@ class DictIterable(FakeQuerySetIterable):
|
|
|
376
344
|
field_names = self.queryset.dict_fields or [field.name for field in self.queryset.model._meta.fields]
|
|
377
345
|
for obj in self.queryset.results:
|
|
378
346
|
yield {
|
|
379
|
-
field_name: extract_field_value(obj, field_name, pk_only=True, suppress_fielddoesnotexist=True)
|
|
347
|
+
field_name: extract_field_value(obj, field_name, pk_only=True, suppress_fielddoesnotexist=True, suppress_nullrelationshipvalueencountered=True)
|
|
380
348
|
for field_name in field_names
|
|
381
349
|
}
|
|
382
350
|
|
|
@@ -385,14 +353,14 @@ class ValuesListIterable(FakeQuerySetIterable):
|
|
|
385
353
|
def __iter__(self):
|
|
386
354
|
field_names = self.queryset.tuple_fields or [field.name for field in self.queryset.model._meta.fields]
|
|
387
355
|
for obj in self.queryset.results:
|
|
388
|
-
yield tuple([extract_field_value(obj, field_name, pk_only=True, suppress_fielddoesnotexist=True) for field_name in field_names])
|
|
356
|
+
yield tuple([extract_field_value(obj, field_name, pk_only=True, suppress_fielddoesnotexist=True, suppress_nullrelationshipvalueencountered=True) for field_name in field_names])
|
|
389
357
|
|
|
390
358
|
|
|
391
359
|
class FlatValuesListIterable(FakeQuerySetIterable):
|
|
392
360
|
def __iter__(self):
|
|
393
361
|
field_name = self.queryset.tuple_fields[0]
|
|
394
362
|
for obj in self.queryset.results:
|
|
395
|
-
yield extract_field_value(obj, field_name, pk_only=True, suppress_fielddoesnotexist=True)
|
|
363
|
+
yield extract_field_value(obj, field_name, pk_only=True, suppress_fielddoesnotexist=True, suppress_nullrelationshipvalueencountered=True)
|
|
396
364
|
|
|
397
365
|
|
|
398
366
|
class FakeQuerySet(object):
|
|
@@ -412,11 +380,41 @@ class FakeQuerySet(object):
|
|
|
412
380
|
new.tuple_fields = self.tuple_fields
|
|
413
381
|
new.iterable_class = self.iterable_class
|
|
414
382
|
return new
|
|
383
|
+
|
|
384
|
+
def resolve_q_object(self, q_object):
|
|
385
|
+
connector = q_object.connector
|
|
386
|
+
filters = []
|
|
415
387
|
|
|
416
|
-
|
|
388
|
+
def test(filters):
|
|
389
|
+
def test_inner(obj):
|
|
390
|
+
result = False
|
|
391
|
+
if connector == Q.AND:
|
|
392
|
+
result = all([test(obj) for test in filters])
|
|
393
|
+
elif connector == Q.OR:
|
|
394
|
+
result = any([test(obj) for test in filters])
|
|
395
|
+
else:
|
|
396
|
+
result = sum([test(obj) for test in filters]) == 1
|
|
397
|
+
if q_object.negated:
|
|
398
|
+
return not result
|
|
399
|
+
return result
|
|
400
|
+
return test_inner
|
|
401
|
+
|
|
402
|
+
for child in q_object.children:
|
|
403
|
+
if isinstance(child, Q):
|
|
404
|
+
filters.append(self.resolve_q_object(child))
|
|
405
|
+
else:
|
|
406
|
+
key_clauses, val = child
|
|
407
|
+
filters.append(_build_test_function_from_filter(self.model, key_clauses.split('__'), val))
|
|
408
|
+
|
|
409
|
+
return test(filters)
|
|
410
|
+
|
|
411
|
+
def _get_filters(self, *args, **kwargs):
|
|
417
412
|
# a list of test functions; objects must pass all tests to be included
|
|
418
413
|
# in the filtered list
|
|
419
414
|
filters = []
|
|
415
|
+
|
|
416
|
+
for q_object in args:
|
|
417
|
+
filters.append(self.resolve_q_object(q_object))
|
|
420
418
|
|
|
421
419
|
for key, val in kwargs.items():
|
|
422
420
|
filters.append(
|
|
@@ -425,8 +423,8 @@ class FakeQuerySet(object):
|
|
|
425
423
|
|
|
426
424
|
return filters
|
|
427
425
|
|
|
428
|
-
def filter(self, **kwargs):
|
|
429
|
-
filters = self._get_filters(**kwargs)
|
|
426
|
+
def filter(self, *args, **kwargs):
|
|
427
|
+
filters = self._get_filters(*args, **kwargs)
|
|
430
428
|
|
|
431
429
|
clone = self.get_clone(results=[
|
|
432
430
|
obj for obj in self.results
|
|
@@ -434,8 +432,8 @@ class FakeQuerySet(object):
|
|
|
434
432
|
])
|
|
435
433
|
return clone
|
|
436
434
|
|
|
437
|
-
def exclude(self, **kwargs):
|
|
438
|
-
filters = self._get_filters(**kwargs)
|
|
435
|
+
def exclude(self, *args, **kwargs):
|
|
436
|
+
filters = self._get_filters(*args, **kwargs)
|
|
439
437
|
|
|
440
438
|
clone = self.get_clone(results=[
|
|
441
439
|
obj for obj in self.results
|
|
@@ -443,8 +441,8 @@ class FakeQuerySet(object):
|
|
|
443
441
|
])
|
|
444
442
|
return clone
|
|
445
443
|
|
|
446
|
-
def get(self, **kwargs):
|
|
447
|
-
clone = self.filter(**kwargs)
|
|
444
|
+
def get(self, *args, **kwargs):
|
|
445
|
+
clone = self.filter(*args, **kwargs)
|
|
448
446
|
result_count = clone.count()
|
|
449
447
|
|
|
450
448
|
if result_count == 0:
|
|
@@ -517,6 +515,18 @@ class FakeQuerySet(object):
|
|
|
517
515
|
sort_by_fields(clone.results, fields)
|
|
518
516
|
return clone
|
|
519
517
|
|
|
518
|
+
def distinct(self, *fields):
|
|
519
|
+
unique_results = []
|
|
520
|
+
if not fields:
|
|
521
|
+
fields = [field.name for field in self.model._meta.fields if not field.primary_key]
|
|
522
|
+
seen_keys = set()
|
|
523
|
+
for result in self.results:
|
|
524
|
+
key = tuple(str(extract_field_value(result, field)) for field in fields)
|
|
525
|
+
if key not in seen_keys:
|
|
526
|
+
seen_keys.add(key)
|
|
527
|
+
unique_results.append(result)
|
|
528
|
+
return self.get_clone(results=unique_results)
|
|
529
|
+
|
|
520
530
|
# a standard QuerySet will store the results in _result_cache on running the query;
|
|
521
531
|
# this is effectively the same as self.results on a FakeQuerySet, and so we'll make
|
|
522
532
|
# _result_cache an alias of self.results for the benefit of Django internals that
|
|
@@ -1,6 +1,18 @@
|
|
|
1
|
+
import datetime
|
|
1
2
|
from functools import lru_cache
|
|
3
|
+
import random
|
|
2
4
|
from django.core.exceptions import FieldDoesNotExist
|
|
3
|
-
from django.db.models import
|
|
5
|
+
from django.db.models import (
|
|
6
|
+
DateField,
|
|
7
|
+
DateTimeField,
|
|
8
|
+
ManyToManyField,
|
|
9
|
+
ManyToManyRel,
|
|
10
|
+
Model,
|
|
11
|
+
TimeField,
|
|
12
|
+
)
|
|
13
|
+
|
|
14
|
+
from modelcluster import datetime_utils
|
|
15
|
+
|
|
4
16
|
|
|
5
17
|
REL_DELIMETER = "__"
|
|
6
18
|
|
|
@@ -9,6 +21,10 @@ class ManyToManyTraversalError(ValueError):
|
|
|
9
21
|
pass
|
|
10
22
|
|
|
11
23
|
|
|
24
|
+
class NullRelationshipValueEncountered(Exception):
|
|
25
|
+
pass
|
|
26
|
+
|
|
27
|
+
|
|
12
28
|
class TraversedRelationship:
|
|
13
29
|
__slots__ = ['from_model', 'field']
|
|
14
30
|
|
|
@@ -62,9 +78,33 @@ def get_model_field(model, name):
|
|
|
62
78
|
subject_model=subject_model,
|
|
63
79
|
)
|
|
64
80
|
)
|
|
65
|
-
|
|
81
|
+
elif getattr(field, "related_model", None):
|
|
66
82
|
traversals.append(TraversedRelationship(subject_model, field))
|
|
67
83
|
subject_model = field.related_model
|
|
84
|
+
elif (
|
|
85
|
+
(
|
|
86
|
+
isinstance(field, DateTimeField)
|
|
87
|
+
and field_name in datetime_utils.DATETIMEFIELD_TRANSFORM_EXPRESSIONS
|
|
88
|
+
) or (
|
|
89
|
+
isinstance(field, DateField)
|
|
90
|
+
and field_name in datetime_utils.DATEFIELD_TRANSFORM_EXPRESSIONS
|
|
91
|
+
) or (
|
|
92
|
+
isinstance(field, TimeField)
|
|
93
|
+
and field_name in datetime_utils.TIMEFIELD_TRANSFORM_EXPRESSIONS
|
|
94
|
+
)
|
|
95
|
+
):
|
|
96
|
+
transform_field_type = datetime_utils.TRANSFORM_FIELD_TYPES[field_name]
|
|
97
|
+
field = transform_field_type()
|
|
98
|
+
break
|
|
99
|
+
else:
|
|
100
|
+
raise FieldDoesNotExist(
|
|
101
|
+
"Failed attempting to traverse from {from_field} (a {from_field_type}) to '{to_field}'."
|
|
102
|
+
.format(
|
|
103
|
+
from_field=subject_model._meta.label + '.' + field.name,
|
|
104
|
+
from_field_type=type(field),
|
|
105
|
+
to_field=field_name,
|
|
106
|
+
)
|
|
107
|
+
)
|
|
68
108
|
try:
|
|
69
109
|
field = subject_model._meta.get_field(field_name)
|
|
70
110
|
except FieldDoesNotExist:
|
|
@@ -76,7 +116,7 @@ def get_model_field(model, name):
|
|
|
76
116
|
return field
|
|
77
117
|
|
|
78
118
|
|
|
79
|
-
def extract_field_value(obj, key, pk_only=False, suppress_fielddoesnotexist=False):
|
|
119
|
+
def extract_field_value(obj, key, pk_only=False, suppress_fielddoesnotexist=False, suppress_nullrelationshipvalueencountered=False):
|
|
80
120
|
"""
|
|
81
121
|
Attempts to extract a field value from ``obj`` matching the ``key`` - which,
|
|
82
122
|
can contain double-underscores (`'__'`) to indicate traversal of relationships
|
|
@@ -89,20 +129,57 @@ def extract_field_value(obj, key, pk_only=False, suppress_fielddoesnotexist=Fals
|
|
|
89
129
|
|
|
90
130
|
By default, ``FieldDoesNotExist`` is raised if the key cannot be mapped to
|
|
91
131
|
a model field. Call the function with ``suppress_fielddoesnotexist=True``
|
|
92
|
-
to
|
|
132
|
+
to instead receive a ``None`` value when this occurs.
|
|
133
|
+
|
|
134
|
+
By default, ``NullRelationshipValueEncountered`` is raised if a ``None``
|
|
135
|
+
value is encountered while attempting to traverse relationships in order to
|
|
136
|
+
access further fields. Call the function with
|
|
137
|
+
``suppress_nullrelationshipvalueencountered`` to instead receive a ``None``
|
|
138
|
+
value when this occurs.
|
|
93
139
|
"""
|
|
94
140
|
source = obj
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
141
|
+
latest_obj = obj
|
|
142
|
+
segments = key.split(REL_DELIMETER)
|
|
143
|
+
for i, segment in enumerate(segments, start=1):
|
|
144
|
+
if (
|
|
145
|
+
(
|
|
146
|
+
isinstance(source, datetime.datetime)
|
|
147
|
+
and segment in datetime_utils.DATETIMEFIELD_TRANSFORM_EXPRESSIONS
|
|
148
|
+
)
|
|
149
|
+
or (
|
|
150
|
+
isinstance(source, datetime.date)
|
|
151
|
+
and segment in datetime_utils.DATEFIELD_TRANSFORM_EXPRESSIONS
|
|
152
|
+
)
|
|
153
|
+
or (
|
|
154
|
+
isinstance(source, datetime.time)
|
|
155
|
+
and segment in datetime_utils.TIMEFIELD_TRANSFORM_EXPRESSIONS
|
|
156
|
+
)
|
|
157
|
+
):
|
|
158
|
+
source = datetime_utils.derive_from_value(source, segment)
|
|
159
|
+
value = source
|
|
160
|
+
elif hasattr(source, segment):
|
|
161
|
+
value = getattr(source, segment)
|
|
162
|
+
if isinstance(value, Model):
|
|
163
|
+
latest_obj = value
|
|
164
|
+
if value is None and i < len(segments):
|
|
165
|
+
if suppress_nullrelationshipvalueencountered:
|
|
166
|
+
return None
|
|
167
|
+
raise NullRelationshipValueEncountered(
|
|
168
|
+
"'{key}' cannot be reached for {obj} because {model_class}.{field_name} "
|
|
169
|
+
"is null.".format(
|
|
170
|
+
key=key,
|
|
171
|
+
obj=repr(obj),
|
|
172
|
+
model_class=latest_obj._meta.label,
|
|
173
|
+
field_name=segment,
|
|
174
|
+
)
|
|
175
|
+
)
|
|
98
176
|
source = value
|
|
99
|
-
continue
|
|
100
177
|
elif suppress_fielddoesnotexist:
|
|
101
178
|
return None
|
|
102
179
|
else:
|
|
103
180
|
raise FieldDoesNotExist(
|
|
104
181
|
"'{name}' is not a valid field name for {model}".format(
|
|
105
|
-
name=
|
|
182
|
+
name=segment, model=type(source)
|
|
106
183
|
)
|
|
107
184
|
)
|
|
108
185
|
if pk_only and hasattr(value, 'pk'):
|
|
@@ -119,6 +196,10 @@ def sort_by_fields(items, fields):
|
|
|
119
196
|
# To get the desired behaviour, we need to order by keys in reverse order
|
|
120
197
|
# See: https://docs.python.org/2/howto/sorting.html#sort-stability-and-complex-sorts
|
|
121
198
|
for key in reversed(fields):
|
|
199
|
+
if key == '?':
|
|
200
|
+
random.shuffle(items)
|
|
201
|
+
continue
|
|
202
|
+
|
|
122
203
|
# Check if this key has been reversed
|
|
123
204
|
reverse = False
|
|
124
205
|
if key[0] == '-':
|
|
@@ -128,7 +209,7 @@ def sort_by_fields(items, fields):
|
|
|
128
209
|
def get_sort_value(item):
|
|
129
210
|
# Use a tuple of (v is not None, v) as the key, to ensure that None sorts before other values,
|
|
130
211
|
# as comparing directly with None breaks on python3
|
|
131
|
-
value = extract_field_value(item, key, pk_only=True, suppress_fielddoesnotexist=True)
|
|
212
|
+
value = extract_field_value(item, key, pk_only=True, suppress_fielddoesnotexist=True, suppress_nullrelationshipvalueencountered=True)
|
|
132
213
|
return (value is not None, value)
|
|
133
214
|
|
|
134
215
|
# Sort items
|
|
@@ -7,7 +7,7 @@ except ImportError:
|
|
|
7
7
|
|
|
8
8
|
setup(
|
|
9
9
|
name='django-modelcluster',
|
|
10
|
-
version='6.
|
|
10
|
+
version='6.4',
|
|
11
11
|
description="Django extension to allow working with 'clusters' of models as a single unit, independently of the database",
|
|
12
12
|
author='Matthew Westcott',
|
|
13
13
|
author_email='matthew.westcott@torchbox.com',
|
|
@@ -15,10 +15,9 @@ setup(
|
|
|
15
15
|
packages=find_packages(exclude=('tests*',)),
|
|
16
16
|
license='BSD',
|
|
17
17
|
long_description=open('README.rst').read(),
|
|
18
|
-
python_requires=">=3.
|
|
18
|
+
python_requires=">=3.9",
|
|
19
19
|
install_requires=[
|
|
20
|
-
"
|
|
21
|
-
"django>=3.2",
|
|
20
|
+
"django>=4.2",
|
|
22
21
|
],
|
|
23
22
|
extras_require={
|
|
24
23
|
'taggit': ['django-taggit>=3.1'],
|
|
@@ -31,11 +30,11 @@ setup(
|
|
|
31
30
|
'Operating System :: OS Independent',
|
|
32
31
|
'Programming Language :: Python',
|
|
33
32
|
'Programming Language :: Python :: 3',
|
|
34
|
-
'Programming Language :: Python :: 3.8',
|
|
35
33
|
'Programming Language :: Python :: 3.9',
|
|
36
34
|
'Programming Language :: Python :: 3.10',
|
|
37
35
|
'Programming Language :: Python :: 3.11',
|
|
38
36
|
'Programming Language :: Python :: 3.12',
|
|
37
|
+
'Programming Language :: Python :: 3.13',
|
|
39
38
|
'Programming Language :: Python :: 3 :: Only',
|
|
40
39
|
'Framework :: Django',
|
|
41
40
|
],
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{django-modelcluster-6.2.1 → django-modelcluster-6.4}/django_modelcluster.egg-info/top_level.txt
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|