Skip to content

Commit

Permalink
Deprecate 'filter_for_reverse_field'
Browse files Browse the repository at this point in the history
  • Loading branch information
Ryan P Kilby authored and carltongibson committed Jul 13, 2018
1 parent 82650aa commit a395d13
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 0 deletions.
8 changes: 8 additions & 0 deletions django_filters/filterset.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,14 @@ def __new__(cls, name, bases, attrs):
new_class._meta = FilterSetOptions(getattr(new_class, 'Meta', None))
new_class.base_filters = new_class.get_filters()

# TODO: remove assertion in 2.1
assert not hasattr(new_class, 'filter_for_reverse_field'), (
"`%(cls)s.filter_for_reverse_field` has been removed. "
"`%(cls)s.filter_for_field` now generates filters for reverse fields. "
"See: https://django-filter.readthedocs.io/en/master/guide/migration.html"
% {'cls': new_class.__name__}
)

return new_class

@classmethod
Expand Down
9 changes: 9 additions & 0 deletions docs/guide/migration.txt
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,15 @@ The ``Filter.lookup_expr`` argument no longer accepts ``None`` or a list of
expressions. Use the :ref:`LookupChoiceFilter <lookup-choice-filter>` instead.


FilterSet ``filter_for_reverse_field`` removed (`#915`__)
---------------------------------------------------------
__ https://github.com/carltongibson/django-filter/pull/915

The ``filter_for_field`` method now generates filters for reverse relationships,
removing the need for ``filter_for_reverse_field``. As a result, reverse
relationships now also obey ``Meta.filter_overrides``.


View attributes renamed (`#867`__)
----------------------------------
__ https://github.com/carltongibson/django-filter/pull/867
Expand Down
13 changes: 13 additions & 0 deletions tests/test_filterset.py
Original file line number Diff line number Diff line change
Expand Up @@ -298,6 +298,19 @@ def test_reverse_relationship_lookup_expr(self):
self.assertEqual(result.lookup_expr, 'isnull')


class FilterSetFilterForReverseFieldTests(TestCase):

def test_method_raises_assertion(self):
msg = ("`F.filter_for_reverse_field` has been removed. "
"`F.filter_for_field` now generates filters for reverse fields.")

with self.assertRaisesMessage(AssertionError, msg):
class F(FilterSet):
@classmethod
def filter_for_reverse_field(cls, field, field_name):
pass


class FilterSetClassCreationTests(TestCase):

def test_no_filters(self):
Expand Down

0 comments on commit a395d13

Please sign in to comment.