Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed #408 - used remote_field instead of deprecated rel #409

Merged
merged 2 commits into from
Jan 20, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 13 additions & 6 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@ matrix:
- python: 2.7
env: TOXENV=py27-1.9
- python: 2.7
env: TOXENV=py35-1.10
env: TOXENV=py27-1.10
- python: 2.7
env: TOXENV=py27-1.11
- python: 3.3
env: TOXENV=py33-1.8
- python: 3.4
Expand All @@ -18,21 +20,26 @@ matrix:
env: TOXENV=py34-1.9
- python: 3.4
env: TOXENV=py34-1.10
- python: 3.5
env: TOXENV=py35-1.8
- python: 3.4
env: TOXENV=py34-1.11
- python: 3.5
env: TOXENV=py35-1.9
- python: 3.5
env: TOXENV=py35-1.10
- python: 2.7
env: TOXENV=py27-master
- python: 3.5
env: TOXENV=py35-1.11
- python: 3.4
env: TOXENV=py34-master
- python: 3.5
env: TOXENV=py35-master
- python: 2.7
env: TOXENV=docs

allow_failures:
- env: TOXENV=py27-master
- env: TOXENV=py27-1.11
- env: TOXENV=py34-1.11
- env: TOXENV=py35-1.11
- env: TOXENV=py34-master
- env: TOXENV=py35-master
install:
- pip install tox
Expand Down
13 changes: 10 additions & 3 deletions django_tables2/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -360,9 +360,16 @@ def get_field(self, model):
field = model._meta.get_field(bit)
except FieldDoesNotExist:
break
if hasattr(field, 'rel') and hasattr(field.rel, 'to'):
model = field.rel.to
continue

if hasattr(field, 'remote_field'):
rel = getattr(field, 'remote_field', None)
model = getattr(rel, 'model', model)

# !!! Support only for Django <= 1.8
# Remove this when support for Django 1.8 is over
else:
rel = getattr(field, 'rel', None)
model = getattr(rel, 'to', model)

return field

Expand Down
2 changes: 1 addition & 1 deletion requirements/django-dev.pip
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
-r common.pip
http://github.com/django/django/tarball/master
https://github.com/django/django/archive/1.11a1.zip
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this intentional? Because this will not continue to be the django development version.

Copy link
Contributor Author

@djk2 djk2 Jan 20, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, this is intentional.
In tox.ini in section [testenv:docs] are installed requirements from /requirements/common.pip and now is not working for master because, currently master is a Django 2.0.
Section for documentation must be tested with python 2.7 and Django < 2.0.

I think that requirements/django-dev.pip and tests for documentation must be changed in future.
Maybe you have any suggestions how to change it?

25 changes: 19 additions & 6 deletions tests/app/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,12 @@ class Person(models.Model):
last_name = models.CharField(max_length=200, verbose_name='surname')

occupation = models.ForeignKey(
'Occupation', related_name='people',
null=True, verbose_name='occupation of the person')
'Occupation',
related_name='people',
null=True,
verbose_name='occupation of the person',
on_delete=models.CASCADE
)

trans_test = models.CharField(
max_length=200, blank=True,
Expand All @@ -42,7 +46,12 @@ class Person(models.Model):

birthdate = models.DateField(null=True)

content_type = models.ForeignKey(ContentType, null=True, blank=True)
content_type = models.ForeignKey(
ContentType,
null=True,
blank=True,
on_delete=models.CASCADE
)
object_id = models.PositiveIntegerField(null=True, blank=True)
foreign_key = GenericForeignKey()

Expand Down Expand Up @@ -70,7 +79,7 @@ class Meta:
@six.python_2_unicode_compatible
class Occupation(models.Model):
name = models.CharField(max_length=200)
region = models.ForeignKey('Region', null=True)
region = models.ForeignKey('Region', null=True, on_delete=models.CASCADE)
boolean = models.BooleanField(null=True)
boolean_with_choices = models.BooleanField(null=True, choices=(
(True, 'Yes'),
Expand All @@ -87,15 +96,19 @@ def __str__(self):
@six.python_2_unicode_compatible
class Region(models.Model):
name = models.CharField(max_length=200)
mayor = models.OneToOneField(Person, null=True)
mayor = models.OneToOneField(Person, null=True, on_delete=models.CASCADE)

def __str__(self):
return self.name


class PersonInformation(models.Model):
person = models.ForeignKey(
Person, related_name='info_list', verbose_name='Information')
Person,
related_name='info_list',
verbose_name='Information',
on_delete=models.CASCADE
)


# -- haystack -----------------------------------------------------------------
Expand Down
2 changes: 1 addition & 1 deletion tests/test_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ class Meta:

class ComplexModel(models.Model):
char = models.CharField(max_length=200)
fk = models.ForeignKey('self')
fk = models.ForeignKey('self', on_delete=models.CASCADE)
m2m = models.ManyToManyField('self')

class Meta:
Expand Down
43 changes: 43 additions & 0 deletions tests/test_rows.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@

import django_tables2 as tables

from django.db import models


def test_bound_rows():
class SimpleTable(tables.Table):
Expand Down Expand Up @@ -54,3 +56,44 @@ class SimpleTable(tables.Table):
assert 'name' in row
assert 'occupation' in row
assert 'gamma' not in row


def test_get_cell_display():

class A(models.Model):
foo = models.CharField(
max_length=1,
choices=(
('a', 'valA'),
('b', 'valB'),
)
)

class Meta:
app_label = 'django_tables2_test'

class B(models.Model):
a = models.ForeignKey(A, on_delete=models.CASCADE)

class Meta:
app_label = 'django_tables2_test'

class C(models.Model):
b = models.ForeignKey(B, on_delete=models.CASCADE)

class Meta:
app_label = 'django_tables2_test'

class Tab(tables.Table):
a = tables.Column(accessor="b.a.foo")

class Meta:
model = C

a = A(foo='a')
b = B(a=a)
c = C(b=b)

tab = Tab([c])
row = tab.rows[0]
assert row.get_cell('a') == 'valA'
5 changes: 3 additions & 2 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ norecursedirs = docs *.egg-info .git example .tox
args_are_paths = false
envlist =
{py27,py33,py34}-{1.8},
{py27,py34,py35}-{1.9,1.10,master},
{py27,py34,py35}-{1.9,1.10,1.11},
{py34,py35}-{master},
docs

[testenv]
Expand All @@ -21,11 +22,11 @@ setenv = PYTHONPATH={toxinidir}
commands =
py.test -rw --cov=django_tables2 --cov-report term-missing
flake8

deps =
1.8: Django>=1.8,<1.9
1.9: Django>=1.9,<1.10
1.10: Django==1.10.1
1.11: Django==1.11a1
pytest-warnings
master: https://github.com/django/django/archive/master.tar.gz
-r{toxinidir}/requirements/common.pip
Expand Down