Skip to content

Commit

Permalink
chore: Django 2.0 compatibility
Browse files Browse the repository at this point in the history
  • Loading branch information
bertonha authored and pennersr committed Jan 24, 2018
1 parent 8123a80 commit 941063c
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 15 deletions.
9 changes: 4 additions & 5 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
language: python
python:
- "2.7"
- "3.4"
- "3.6"
env:
- TOX_ENV=py27-django19
- TOX_ENV=py34-django19
- TOX_ENV=py27-django110
- TOX_ENV=py34-django110
- TOX_ENV=py27-django111
- TOX_ENV=py36-django111
- TOX_ENV=py36-django20
install:
- pip install tox
- pip install "coverage>=3.7.1" coveralls
Expand Down
3 changes: 2 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ def read_files(*filenames):
packages=find_packages(),
include_package_data=True,
install_requires=[
'django>=1.9',
'django>=1.11',
'pytz'
],
cmdclass={'test': DjangoTests},
Expand All @@ -67,6 +67,7 @@ def read_files(*filenames):
'Programming Language :: Python :: 2.7',
'Programming Language :: Python :: 3.3',
'Programming Language :: Python :: 3.4',
'Programming Language :: Python :: 3.6',
'Topic :: Software Development :: Libraries :: Application Frameworks',
'Topic :: Software Development :: Libraries :: Python Modules',
],
Expand Down
8 changes: 4 additions & 4 deletions tox.ini
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
[tox]
distribute = False
envlist =
{py27,py34}-django19
{py27,py34}-django110
{py27,py36}-django111
py36-django20


[testenv]
setenv = DJANGO_SETTINGS_MODULE=trackstats.tests.settings
usedevelop = True
deps =
django19: Django==1.9.9
django110: Django==1.10
django111: Django==1.11.8
django20: Django==2.0.1
pytz
coverage
commands =
Expand Down
2 changes: 1 addition & 1 deletion trackstats/tests/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@


class Comment(models.Model):
user = models.ForeignKey('auth.User')
user = models.ForeignKey('auth.User', on_delete=models.CASCADE)
timestamp = models.DateTimeField(default=timezone.now)
12 changes: 8 additions & 4 deletions trackstats/trackers.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,12 +84,16 @@ def track(self, qs):
is_datetime = isinstance(qs.model._meta.get_field(
self.date_field), models.DateTimeField)
if is_datetime:
date_sql, tz_params = connection.ops.datetime_cast_date_sql(
date_sql = connection.ops.datetime_cast_date_sql(
self.date_field,
tzname)
vals = qs.extra(
select={"ts_date": date_sql},
select_params=tz_params)
# before django 2.0 it returns a tuple
if isinstance(date_sql, tuple):
vals = qs.extra(
select={"ts_date": date_sql[0]},
select_params=date_sql[1])
else:
vals = qs.extra(select={"ts_date": date_sql})
start_dt = datetime.combine(
start_date, time()) - timedelta(days=1)
if tzname:
Expand Down

0 comments on commit 941063c

Please sign in to comment.