Skip to content

Commit 37709fd

Browse files
authored
Merge pull request #12 from novafloss/9-support-django19
Adding Django 1.9 support
2 parents 935690f + 03912f8 commit 37709fd

File tree

4 files changed

+10
-6
lines changed

4 files changed

+10
-6
lines changed

.travis.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ env:
44
- TOX_ENV=py27-django16
55
- TOX_ENV=py27-django17
66
- TOX_ENV=py27-django18
7+
- TOX_ENV=py27-django19
78
- TOX_ENV=flake8
89
script: tox -e $TOX_ENV
910
install:

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
## master (unreleased)
44

5-
- Nothing changed yet.
5+
- Added Django 1.9 suport (#9).
66

77
## 1.0.0 (2016-06-23)
88

chunkator/__init__.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22
Toolbox for chunking / slicing querysets
33
"""
44

5-
from django.db.models.query import ValuesQuerySet
6-
75

86
class MissingPkFieldException(Exception):
97
"""
@@ -23,7 +21,10 @@ def chunkator(source_qs, chunk_size, query_log=None):
2321
CPU-and-RAM-consuming ``len(queryset)`` query.
2422
"""
2523
pk = None
26-
if isinstance(source_qs, ValuesQuerySet):
24+
# In django 1.9, _fields is always present and `None` if 'values()' is used
25+
# In Django 1.8 and below, _fields will only be present if using `values()`
26+
has_fields = hasattr(source_qs, '_fields') and source_qs._fields
27+
if has_fields:
2728
if "pk" not in source_qs._fields:
2829
raise MissingPkFieldException("The values() call must include the `pk` field") # noqa
2930

@@ -37,7 +38,8 @@ def chunkator(source_qs, chunk_size, query_log=None):
3738
query_log.write('{page.query}\n'.format(page=page))
3839
nb_items = 0
3940
for item in page:
40-
if isinstance(queryset, ValuesQuerySet):
41+
# source_qs._fields exists *and* is not none when using "values()"
42+
if has_fields:
4143
pk = item["pk"]
4244
else:
4345
pk = item.pk

tox.ini

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
[tox]
2-
envlist = {py27,py34}-django{16,17,18},flake8
2+
envlist = {py27,py34}-django{16,17,18,19},flake8
33

44
[testenv]
55
usedevelop = True
66
deps =
77
django16: Django>=1.6,<1.7
88
django17: Django>=1.7,<1.8
99
django18: Django>=1.8,<1.9
10+
django19: Django>=1.9,<1.10
1011
flake8: flake8
1112
commands =
1213
pip install -e demo/

0 commit comments

Comments
 (0)