{"action":"created","issue":{"url":"https://api.github.com/repos/craigds/django-typed-models/issues/42","repository_url":"https://api.github.com/repos/craigds/django-typed-models","labels_url":"https://api.github.com/repos/craigds/django-typed-models/issues/42/labels{/name}","comments_url":"https://api.github.com/repos/craigds/django-typed-models/issues/42/comments","events_url":"https://api.github.com/repos/craigds/django-typed-models/issues/42/events","html_url":"https://github.com/craigds/django-typed-models/issues/42","id":297528945,"number":42,"title":"Subclass form validation raises FieldDoesNotExist","user":{"login":"ppo","id":117100,"avatar_url":"https://avatars3.githubusercontent.com/u/117100?v=4","gravatar_id":"","url":"https://api.github.com/users/ppo","html_url":"https://github.com/ppo","followers_url":"https://api.github.com/users/ppo/followers","following_url":"https://api.github.com/users/ppo/following{/other_user}","gists_url":"https://api.github.com/users/ppo/gists{/gist_id}","starred_url":"https://api.github.com/users/ppo/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ppo/subscriptions","organizations_url":"https://api.github.com/users/ppo/orgs","repos_url":"https://api.github.com/users/ppo/repos","events_url":"https://api.github.com/users/ppo/events{/privacy}","received_events_url":"https://api.github.com/users/ppo/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":2,"created_at":"2018-02-15T17:21:40Z","updated_at":"2018-02-16T09:33:05Z","closed_at":"2018-02-15T21:08:04Z","author_association":"NONE","body":"```\r\nclass Parent(TypedModel):\r\n    a = models.CharField(...)\r\n\r\nclass Child1(Parent):\r\n    b = models.OneToOneField(...)\r\n\r\nclass Child2(Parent):\r\n    pass\r\n```\r\n\r\nCreating a `Child2` via the admin, using a model form, raises:  \r\n`django.core.exceptions.FieldDoesNotExist: Child2 has no field named 'b'`\r\n\r\nThe problem comes from `db.models.base.Model._get_unique_checks()` that gets `_meta.local_fields` from parent classes. `Parent` having all fields from all subclasses, `db.models.base.Model._perform_unique_checks()` raises that error.\r\n\r\nI fixed that problem as follows but maybe someone will have a better solution…\r\n\r\n```\r\nclass Parent(TypedModel):\r\n    def _perform_unique_checks(self, unique_checks):\r\n        clean_unique_checks = []\r\n        for model_class, unique_check in unique_checks:\r\n            clean_unique_check = []\r\n            for field_name in unique_check:\r\n                try:\r\n                    clean_unique_check.append(self._meta.get_field(field_name))\r\n                except FieldDoesNotExist:\r\n                    pass\r\n            if len(clean_unique_check):\r\n                clean_unique_checks.append((model_class, clean_unique_check))\r\n\r\n        return super()._perform_unique_checks(clean_unique_checks)\r\n```"},"comment":{"url":"https://api.github.com/repos/craigds/django-typed-models/issues/comments/366185807","html_url":"https://github.com/craigds/django-typed-models/issues/42#issuecomment-366185807","issue_url":"https://api.github.com/repos/craigds/django-typed-models/issues/42","id":366185807,"user":{"login":"ppo","id":117100,"avatar_url":"https://avatars3.githubusercontent.com/u/117100?v=4","gravatar_id":"","url":"https://api.github.com/users/ppo","html_url":"https://github.com/ppo","followers_url":"https://api.github.com/users/ppo/followers","following_url":"https://api.github.com/users/ppo/following{/other_user}","gists_url":"https://api.github.com/users/ppo/gists{/gist_id}","starred_url":"https://api.github.com/users/ppo/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ppo/subscriptions","organizations_url":"https://api.github.com/users/ppo/orgs","repos_url":"https://api.github.com/users/ppo/repos","events_url":"https://api.github.com/users/ppo/events{/privacy}","received_events_url":"https://api.github.com/users/ppo/received_events","type":"User","site_admin":false},"created_at":"2018-02-16T09:33:05Z","updated_at":"2018-02-16T09:33:05Z","author_association":"NONE","body":"@craigds yeah but defining that field in the parent is not clean ;-)"}}
{"actor":{"display_login":"ppo"}}