Skip to content

Commit

Permalink
Merge b114f07 into 2504596
Browse files Browse the repository at this point in the history
  • Loading branch information
georgema1982 committed Feb 16, 2021
2 parents 2504596 + b114f07 commit ad7f7b9
Show file tree
Hide file tree
Showing 7 changed files with 45 additions and 21 deletions.
2 changes: 1 addition & 1 deletion .cookiecutterrc
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ cookiecutter:
email: contact@ionelmc.ro
full_name: Ionel Cristian Mărieș
github_username: ionelmc
landscape: yes
landscape: no
license: BSD 2-Clause License
linter: flake8
package_name: prefetch
Expand Down
20 changes: 17 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ matrix:
- python: '3.4'
env:
- TOXENV=py34-dj111,report,coveralls,codecov
- python: '3.4'
env:
- TOXENV=py34-dj20,report,coveralls,codecov
- python: '3.5'
env:
- TOXENV=py35-dj19,report,coveralls,codecov
Expand All @@ -37,6 +40,9 @@ matrix:
- python: '3.5'
env:
- TOXENV=py35-dj111,report,coveralls,codecov
- python: '3.5'
env:
- TOXENV=py35-dj20,report,coveralls,codecov
- python: '3.6'
env:
- TOXENV=py36-dj19,report,coveralls,codecov
Expand All @@ -46,6 +52,9 @@ matrix:
- python: '3.6'
env:
- TOXENV=py36-dj111,report,coveralls,codecov
- python: '3.6'
env:
- TOXENV=py36-dj20,report,coveralls,codecov
- python: '3.7'
dist: xenial
sudo: required
Expand All @@ -61,13 +70,18 @@ matrix:
sudo: required
env:
- TOXENV=py37-dj111,report,coveralls,codecov
- python: 'pypy-5.4'
- python: '3.7'
dist: xenial
sudo: required
env:
- TOXENV=py37-dj20,report,coveralls,codecov
- python: 'pypy2'
env:
- TOXENV=pypy-dj19,report,coveralls,codecov
- python: 'pypy-5.4'
- python: 'pypy2'
env:
- TOXENV=pypy-dj110,report,coveralls,codecov
- python: 'pypy-5.4'
- python: 'pypy2'
env:
- TOXENV=pypy-dj111,report,coveralls,codecov
before_install:
Expand Down
5 changes: 5 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@
Changelog
=========

1.2.2 (2021-02-14)
------------------

* Added support for Django 2.0

1.2.1 (2018-09-04)
------------------

Expand Down
6 changes: 1 addition & 5 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ Overview
* - tests
- | |travis| |requires|
| |coveralls| |codecov|
| |landscape| |scrutinizer| |codacy| |codeclimate|
| |scrutinizer| |codacy| |codeclimate|
* - package
- | |version| |wheel| |supported-versions| |supported-implementations|
| |commits-since|
Expand All @@ -37,10 +37,6 @@ Overview
:alt: Coverage Status
:target: https://codecov.io/github/ionelmc/django-prefetch

.. |landscape| image:: https://landscape.io/github/ionelmc/django-prefetch/master/landscape.svg?style=flat
:target: https://landscape.io/github/ionelmc/django-prefetch/master
:alt: Code Quality Status

.. |codacy| image:: https://img.shields.io/codacy/REPLACE_WITH_PROJECT_ID.svg
:target: https://www.codacy.com/app/ionelmc/django-prefetch
:alt: Codacy Code Quality Status
Expand Down
18 changes: 13 additions & 5 deletions src/prefetch.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@
import time
from logging import getLogger

import django
from django.db import models
from django.db.models import query
from django.db.models.fields.related_descriptors import ForwardManyToOneDescriptor

__version__ = '1.2.1'
__version__ = '1.2.2'

logger = getLogger(__name__)

Expand Down Expand Up @@ -75,10 +76,17 @@ def __init__(self, model=None, query=None, using=None,
self.prefetch_definitions = prefetch_definitions
self._iterable_class = PrefetchIterable

def _clone(self, **kwargs):
return super(PrefetchQuerySet, self). \
_clone(_prefetch=self._prefetch,
prefetch_definitions=self.prefetch_definitions, **kwargs)
if django.VERSION < (2, 0):
def _clone(self, **kwargs):
return super(PrefetchQuerySet, self). \
_clone(_prefetch=self._prefetch,
prefetch_definitions=self.prefetch_definitions, **kwargs)
else:
def _clone(self):
c = super(PrefetchQuerySet, self)._clone()
c._prefetch = self._prefetch
c.prefetch_definitions = self.prefetch_definitions
return c

def prefetch(self, *names):
obj = self._clone()
Expand Down
8 changes: 4 additions & 4 deletions tests/test_app/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,8 +108,8 @@ class Meta:

name = models.CharField(max_length=100)
created = models.DateTimeField(auto_now_add=True)
author = models.ForeignKey(Author)
publisher = models.ForeignKey(Publisher, null=True)
author = models.ForeignKey(Author, models.CASCADE)
publisher = models.ForeignKey(Publisher, models.CASCADE, null=True)

tags = models.ManyToManyField(Tag)

Expand Down Expand Up @@ -157,8 +157,8 @@ def selected_tags(self):


class BookNote(models.Model):
book = models.ForeignKey("Book", null=True)
bogus = models.ForeignKey("Book", null=True, related_name="+")
book = models.ForeignKey("Book", models.CASCADE, null=True)
bogus = models.ForeignKey("Book", models.CASCADE, null=True, related_name="+")
notes = models.TextField()

objects = PrefetchManager()
7 changes: 4 additions & 3 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
envlist =
clean,
check,
{py27,py34,py35,py36,py37,pypy}-{dj19,dj110,dj111},
{py27,py34,py35,py36,py37,pypy}-{dj19,dj110,dj111,dj20},
report,
docs

Expand All @@ -25,13 +25,14 @@ passenv =
*
usedevelop = false
deps =
pytest
pytest-django
pytest==3.10.1
pytest-django==3.2.1
pytest-travis-fold
pytest-cov
dj19: Django==1.9.13
dj110: Django==1.10.8
dj111: Django==1.11.15
dj20: Django==2.0.13
commands =
{posargs:pytest --cov --cov-report=term-missing -vv tests}

Expand Down

0 comments on commit ad7f7b9

Please sign in to comment.