Skip to content

Commit

Permalink
Replaced usage of deprecated function get_fields_with_model with new … (
Browse files Browse the repository at this point in the history
#3052)

* Replaced usage of deprecated function get_fields_with_model with new local function, which does the same thing.

* Added comment explaining why get_fields_with_model was replaced.

* Cleaned up comment in get_fields_with_model. Previously failed to pass lint test.

* Made small changes to docstring to attempt to pass linting test.
  • Loading branch information
josejrobles authored and agjohnson committed Dec 5, 2017
1 parent d7736e1 commit 4b01021
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion readthedocs/builds/version_slug.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,22 @@
from builtins import range


def get_fields_with_model(cls):
"""
Replace deprecated function of the same name in Model._meta.
This replaces deprecated function (as of Django 1.10) in
Model._meta as prescrived in the Django docs.
https://docs.djangoproject.com/en/1.11/ref/models/meta/#migrating-from-the-old-api
"""
return [
(f, f.model if f.model != cls else None)
for f in cls._meta.get_fields()
if not f.is_relation or f.one_to_one or
(f.many_to_one and f.related_model)
]


# Regex breakdown:
# [a-z0-9] -- start with alphanumeric value
# [-._a-z0-9] -- allow dash, dot, underscore, digit, lowercase ascii
Expand Down Expand Up @@ -59,7 +75,7 @@ def __init__(self, *args, **kwargs):

def get_queryset(self, model_cls, slug_field):
# pylint: disable=protected-access
for field, model in model_cls._meta.get_fields_with_model():
for field, model in get_fields_with_model(model_cls):
if model and field == slug_field:
return model._default_manager.all()
return model_cls._default_manager.all()
Expand Down

0 comments on commit 4b01021

Please sign in to comment.