{"action":"created","issue":{"url":"https://api.github.com/repos/landscapeio/pylint-django/issues/35","repository_url":"https://api.github.com/repos/landscapeio/pylint-django","labels_url":"https://api.github.com/repos/landscapeio/pylint-django/issues/35/labels{/name}","comments_url":"https://api.github.com/repos/landscapeio/pylint-django/issues/35/comments","events_url":"https://api.github.com/repos/landscapeio/pylint-django/issues/35/events","html_url":"https://github.com/landscapeio/pylint-django/issues/35","id":52609869,"number":35,"title":"ForeignKey transform doesn't work when the class is specified by a string","user":{"login":"chris-martin","id":399718,"avatar_url":"https://avatars.githubusercontent.com/u/399718?v=3","gravatar_id":"","url":"https://api.github.com/users/chris-martin","html_url":"https://github.com/chris-martin","followers_url":"https://api.github.com/users/chris-martin/followers","following_url":"https://api.github.com/users/chris-martin/following{/other_user}","gists_url":"https://api.github.com/users/chris-martin/gists{/gist_id}","starred_url":"https://api.github.com/users/chris-martin/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/chris-martin/subscriptions","organizations_url":"https://api.github.com/users/chris-martin/orgs","repos_url":"https://api.github.com/users/chris-martin/repos","events_url":"https://api.github.com/users/chris-martin/events{/privacy}","received_events_url":"https://api.github.com/users/chris-martin/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":4,"created_at":"2014-12-21T23:35:14Z","updated_at":"2016-09-23T08:09:54Z","closed_at":null,"body":"Pylint-django works as advertised on a field declared like this:\r\n\r\n```py\r\nfield = ForeignKey(TheModel)\r\n```\r\n\r\nBut not on this equivalent field:\r\n\r\n```py\r\nfield = ForeignKey('appname.TheModel')\r\n```"},"comment":{"url":"https://api.github.com/repos/landscapeio/pylint-django/issues/comments/249129654","html_url":"https://github.com/landscapeio/pylint-django/issues/35#issuecomment-249129654","issue_url":"https://api.github.com/repos/landscapeio/pylint-django/issues/35","id":249129654,"user":{"login":"NotSqrt","id":1997005,"avatar_url":"https://avatars.githubusercontent.com/u/1997005?v=3","gravatar_id":"","url":"https://api.github.com/users/NotSqrt","html_url":"https://github.com/NotSqrt","followers_url":"https://api.github.com/users/NotSqrt/followers","following_url":"https://api.github.com/users/NotSqrt/following{/other_user}","gists_url":"https://api.github.com/users/NotSqrt/gists{/gist_id}","starred_url":"https://api.github.com/users/NotSqrt/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/NotSqrt/subscriptions","organizations_url":"https://api.github.com/users/NotSqrt/orgs","repos_url":"https://api.github.com/users/NotSqrt/repos","events_url":"https://api.github.com/users/NotSqrt/events{/privacy}","received_events_url":"https://api.github.com/users/NotSqrt/received_events","type":"User","site_admin":false},"created_at":"2016-09-23T08:09:54Z","updated_at":"2016-09-23T08:09:54Z","body":"I went another way:\r\nI upgraded the ``infer_key_classes`` function with:\r\n\r\n```python\r\ndef infer_key_classes(node, context=None):\r\n    for arg in node.args:\r\n        # typically the class of the foreign key will\r\n        # be the first argument, so we'll go from left to right\r\n        if isinstance(arg, (nodes.Name, nodes.Getattr)):\r\n             # as before\r\n        elif isinstance(arg, nodes.Const):\r\n            try:\r\n                model_name = arg.value.split('.')[-1]  # can be 'Model' or 'app.Model'\r\n            except AttributeError:\r\n                break\r\n\r\n            for module in MANAGER.astroid_cache.values():\r\n                if model_name in module.locals:\r\n                    class_defs = [\r\n                        module_node for module_node in module.lookup(model_name)[1]\r\n                        if isinstance(module_node, nodes.ClassDef)\r\n                        and node_is_subclass(module_node, 'django.db.models.base.Model')\r\n                    ]\r\n                    if class_defs:\r\n                        return iter([instantiate_class(class_defs[0])()])\r\n\r\n        # as before\r\n```\r\n\r\nwhich basically looks up all classes found in all modules to find a subclass of ``Model`` that has the expected name."}}
{"actor":{"display_login":"NotSqrt"}}