Skip to content

Commit

Permalink
Stopped using the deprecated get_(fields|m2m)_with_model() APIs.
Browse files Browse the repository at this point in the history
  • Loading branch information
charettes committed Sep 1, 2015
1 parent e26dc7e commit 7471543
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 12 deletions.
11 changes: 3 additions & 8 deletions mutant/models/model/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import pickle
from hashlib import md5
from itertools import chain

from django.apps import apps
from django.contrib.contenttypes.models import ContentType
Expand All @@ -21,7 +20,7 @@
from ...db.models import MutableModel
from ...signals import mutable_class_prepared
from ...state import handler as state_handler
from ...utils import get_db_table, remove_from_app_cache
from ...utils import get_db_table, get_fields, remove_from_app_cache
from ..ordered import OrderedModel
from .managers import ModelDefinitionManager

Expand Down Expand Up @@ -388,12 +387,8 @@ def get_declared_fields(self):
if opts.abstract:
# Add fields inherited from base's abstract parent and
# local fields.
base_fields = chain(
opts.get_fields_with_model(),
opts.get_m2m_with_model()
)
for field, model in base_fields:
if model is None or model._meta.abstract:
for field in get_fields(opts):
if field.model is self.base or field.model._meta.abstract:
clone = field.clone()
clone.set_attributes_from_name(field.name)
fields.append(clone)
Expand Down
15 changes: 11 additions & 4 deletions mutant/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,11 +85,9 @@ def remove_from_app_cache(model_class, quiet=False):


def unreference_model(model):
opts = model._meta
for field, field_model in chain(opts.get_fields_with_model(),
opts.get_m2m_with_model()):
for field in get_fields(model._meta):
rel = getattr(field, 'rel', None)
if field_model is None and rel:
if field.model is model and rel:
to = rel.to
if isinstance(to, models.base.ModelBase):
clear_opts_related_cache(to)
Expand Down Expand Up @@ -170,6 +168,9 @@ def choices_from_dict(choices):


if django.VERSION >= (1, 8):
def get_fields(opts):
return opts.get_fields()

def clear_opts_related_cache(model_class):
opts = model_class._meta
children = [
Expand All @@ -180,6 +181,12 @@ def clear_opts_related_cache(model_class):
for child in children:
clear_opts_related_cache(child)
else:
def get_fields(opts):
return chain(
opts.fields,
opts.many_to_many
)

_opts_related_cache_attrs = [
'_related_objects_cache',
'_related_objects_proxy_cache',
Expand Down

0 comments on commit 7471543

Please sign in to comment.