Skip to content

Commit

Permalink
Fixes carltongibson#209, Fix replaced model in Django 1.8
Browse files Browse the repository at this point in the history
  • Loading branch information
tricoder42 committed Jan 17, 2015
1 parent f935a07 commit 32d1a3b
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions django_filters/filterset.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
from django.core.validators import EMPTY_VALUES
from django.db import models
from django.db.models.fields import FieldDoesNotExist
from django.db.models.related import RelatedObject
from django.utils import six
from django.utils.text import capfirst
from django.utils.translation import ugettext as _
Expand All @@ -26,6 +25,12 @@
# Django < 1.5 fallback
from django.utils.datastructures import SortedDict as OrderedDict # noqa

try:
from django.db.models.related import RelatedObject as ForeignObjectRel
except ImportError: # pragma: nocover
# Django >= 1.8 replaces RelatedObject with ForeignObjectRel
from django.db.models.fields.related import ForeignObjectRel


from .filters import (Filter, CharFilter, BooleanFilter,
ChoiceFilter, DateFilter, DateTimeFilter, TimeFilter, ModelChoiceFilter,
Expand Down Expand Up @@ -73,7 +78,7 @@ def get_model_field(model, f):
rel = opts.get_field_by_name(name)[0]
except FieldDoesNotExist:
return None
if isinstance(rel, RelatedObject):
if isinstance(rel, ForeignObjectRel):
model = rel.model
opts = rel.opts
else:
Expand Down Expand Up @@ -103,7 +108,7 @@ def filters_for_model(model, fields=None, exclude=None, filter_for_field=None,
if field is None:
field_dict[f] = None
continue
if isinstance(field, RelatedObject):
if isinstance(field, ForeignObjectRel):
filter_ = filter_for_reverse_field(field, f)
if filter_:
field_dict[f] = filter_
Expand Down Expand Up @@ -426,7 +431,7 @@ def filter_for_field(cls, f, name, lookup_type='exact'):
@classmethod
def filter_for_reverse_field(cls, f, name):
rel = f.field.rel
queryset = f.model._default_manager.all()
queryset = f.field.model._default_manager.all()
default = {
'name': name,
'label': capfirst(rel.related_name),
Expand Down

0 comments on commit 32d1a3b

Please sign in to comment.