{"action":"created","comment":{"url":"https://api.github.com/repos/cos-labs/collections-service/pulls/comments/142790555","pull_request_review_id":67204766,"id":142790555,"diff_hunk":"@@ -157,6 +193,125 @@ class Parameter(ModelSerializer):\n         required=False\n     )\n \n+\n+    def create(self, validated_data):\n+        \"\"\"\n+        We have a bit of extra checking around this in order to provide\n+        descriptive messages when something goes wrong, but this method is\n+        essentially just:\n+            return ExampleModel.objects.create(**validated_data)\n+        If there are many to many fields present on the instance then they\n+        cannot be set until the model is instantiated, in which case the\n+        implementation is like so:\n+            example_relationship = validated_data.pop('example_relationship')\n+            instance = ExampleModel.objects.create(**validated_data)\n+            instance.example_relationship = example_relationship\n+            return instance\n+        The default implementation also does not handle nested relationships.\n+        If you want to support writable nested relationships you'll need\n+        to write an explicit `.create()` method.\n+        \"\"\"\n+        raise_errors_on_nested_writes('create', self, validated_data)\n+\n+        ModelClass = self.Meta.model\n+\n+        # Remove many-to-many relationships from validated_data.\n+        # They are not valid arguments to the default `.create()` method,\n+        # as they require that the instance has already been saved.\n+        info = model_meta.get_field_info(ModelClass)\n+        many_to_many = {}\n+        for field_name, relation_info in info.relations.items():\n+            if relation_info.to_many and (field_name in validated_data):\n+                many_to_many[field_name] = validated_data.pop(field_name)\n+\n+        try:\n+            instance = ModelClass.objects.create(**validated_data)\n+        except TypeError:\n+            tb = traceback.format_exc()\n+            msg = (\n+                'Got a `TypeError` when calling `%s.objects.create()`. '\n+                'This may be because you have a writable field on the '\n+                'serializer class that is not a valid argument to '\n+                '`%s.objects.create()`. You may need to make the field '\n+                'read-only, or override the %s.create() method to handle '\n+                'this correctly.\\nOriginal exception was:\\n %s' %\n+                (\n+                    ModelClass.__name__,\n+                    ModelClass.__name__,\n+                    self.__class__.__name__,\n+                    tb\n+                )\n+            )\n+            raise TypeError(msg)\n+\n+        # Save many-to-many relationships after the instance is created.\n+        if many_to_many:\n+            for field_name, value in many_to_many.items():\n+\n+                # If the m2m has a model defined as a through table, then\n+                # relations cannot be added by that relationship's .add() method,\n+                # but should be created using the model's constructor.\n+                # This loop checks to ensure that if the relation does not exist\n+                # it is created. The way this is set up now, it requires the relation\n+                # to be unique.","path":"workflow/serializers.py","position":209,"original_position":209,"commit_id":"d3577e4975c7ab9029dfb44009fb7d221a79a5a4","original_commit_id":"7a0b39b09acf2d52d165651c2b0b46598a4bc0d5","user":{"login":"cameronblandford","id":7365276,"avatar_url":"https://avatars0.githubusercontent.com/u/7365276?v=4","gravatar_id":"","url":"https://api.github.com/users/cameronblandford","html_url":"https://github.com/cameronblandford","followers_url":"https://api.github.com/users/cameronblandford/followers","following_url":"https://api.github.com/users/cameronblandford/following{/other_user}","gists_url":"https://api.github.com/users/cameronblandford/gists{/gist_id}","starred_url":"https://api.github.com/users/cameronblandford/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/cameronblandford/subscriptions","organizations_url":"https://api.github.com/users/cameronblandford/orgs","repos_url":"https://api.github.com/users/cameronblandford/repos","events_url":"https://api.github.com/users/cameronblandford/events{/privacy}","received_events_url":"https://api.github.com/users/cameronblandford/received_events","type":"User","site_admin":false},"body":":+1:","created_at":"2017-10-04T20:57:15Z","updated_at":"2017-10-04T20:57:15Z","html_url":"https://github.com/cos-labs/collections-service/pull/50#discussion_r142790555","pull_request_url":"https://api.github.com/repos/cos-labs/collections-service/pulls/50","author_association":"COLLABORATOR","_links":{"self":{"href":"https://api.github.com/repos/cos-labs/collections-service/pulls/comments/142790555"},"html":{"href":"https://github.com/cos-labs/collections-service/pull/50#discussion_r142790555"},"pull_request":{"href":"https://api.github.com/repos/cos-labs/collections-service/pulls/50"}},"in_reply_to_id":142742060},"pull_request":{"url":"https://api.github.com/repos/cos-labs/collections-service/pulls/50","id":143226668,"html_url":"https://github.com/cos-labs/collections-service/pull/50","diff_url":"https://github.com/cos-labs/collections-service/pull/50.diff","patch_url":"https://github.com/cos-labs/collections-service/pull/50.patch","issue_url":"https://api.github.com/repos/cos-labs/collections-service/issues/50","number":50,"state":"open","locked":false,"title":"Add fields for json, import from json","user":{"login":"birdbrained","id":1523817,"avatar_url":"https://avatars0.githubusercontent.com/u/1523817?v=4","gravatar_id":"","url":"https://api.github.com/users/birdbrained","html_url":"https://github.com/birdbrained","followers_url":"https://api.github.com/users/birdbrained/followers","following_url":"https://api.github.com/users/birdbrained/following{/other_user}","gists_url":"https://api.github.com/users/birdbrained/gists{/gist_id}","starred_url":"https://api.github.com/users/birdbrained/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/birdbrained/subscriptions","organizations_url":"https://api.github.com/users/birdbrained/orgs","repos_url":"https://api.github.com/users/birdbrained/repos","events_url":"https://api.github.com/users/birdbrained/events{/privacy}","received_events_url":"https://api.github.com/users/birdbrained/received_events","type":"User","site_admin":false},"body":"","created_at":"2017-09-26T19:49:51Z","updated_at":"2017-10-04T20:57:15Z","closed_at":null,"merged_at":null,"merge_commit_sha":"f13fed2eb688a5e8b7b4b75efc3958522f058dd6","assignee":null,"assignees":[],"requested_reviewers":[],"milestone":null,"commits_url":"https://api.github.com/repos/cos-labs/collections-service/pulls/50/commits","review_comments_url":"https://api.github.com/repos/cos-labs/collections-service/pulls/50/comments","review_comment_url":"https://api.github.com/repos/cos-labs/collections-service/pulls/comments{/number}","comments_url":"https://api.github.com/repos/cos-labs/collections-service/issues/50/comments","statuses_url":"https://api.github.com/repos/cos-labs/collections-service/statuses/d3577e4975c7ab9029dfb44009fb7d221a79a5a4","head":{"label":"birdbrained:fix-migrations","ref":"fix-migrations","sha":"d3577e4975c7ab9029dfb44009fb7d221a79a5a4","user":{"login":"birdbrained","id":1523817,"avatar_url":"https://avatars0.githubusercontent.com/u/1523817?v=4","gravatar_id":"","url":"https://api.github.com/users/birdbrained","html_url":"https://github.com/birdbrained","followers_url":"https://api.github.com/users/birdbrained/followers","following_url":"https://api.github.com/users/birdbrained/following{/other_user}","gists_url":"https://api.github.com/users/birdbrained/gists{/gist_id}","starred_url":"https://api.github.com/users/birdbrained/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/birdbrained/subscriptions","organizations_url":"https://api.github.com/users/birdbrained/orgs","repos_url":"https://api.github.com/users/birdbrained/repos","events_url":"https://api.github.com/users/birdbrained/events{/privacy}","received_events_url":"https://api.github.com/users/birdbrained/received_events","type":"User","site_admin":false},"repo":{"id":95930497,"name":"collections-service","full_name":"birdbrained/collections-service","owner":{"login":"birdbrained","id":1523817,"avatar_url":"https://avatars0.githubusercontent.com/u/1523817?v=4","gravatar_id":"","url":"https://api.github.com/users/birdbrained","html_url":"https://github.com/birdbrained","followers_url":"https://api.github.com/users/birdbrained/followers","following_url":"https://api.github.com/users/birdbrained/following{/other_user}","gists_url":"https://api.github.com/users/birdbrained/gists{/gist_id}","starred_url":"https://api.github.com/users/birdbrained/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/birdbrained/subscriptions","organizations_url":"https://api.github.com/users/birdbrained/orgs","repos_url":"https://api.github.com/users/birdbrained/repos","events_url":"https://api.github.com/users/birdbrained/events{/privacy}","received_events_url":"https://api.github.com/users/birdbrained/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/birdbrained/collections-service","description":null,"fork":true,"url":"https://api.github.com/repos/birdbrained/collections-service","forks_url":"https://api.github.com/repos/birdbrained/collections-service/forks","keys_url":"https://api.github.com/repos/birdbrained/collections-service/keys{/key_id}","collaborators_url":"https://api.github.com/repos/birdbrained/collections-service/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/birdbrained/collections-service/teams","hooks_url":"https://api.github.com/repos/birdbrained/collections-service/hooks","issue_events_url":"https://api.github.com/repos/birdbrained/collections-service/issues/events{/number}","events_url":"https://api.github.com/repos/birdbrained/collections-service/events","assignees_url":"https://api.github.com/repos/birdbrained/collections-service/assignees{/user}","branches_url":"https://api.github.com/repos/birdbrained/collections-service/branches{/branch}","tags_url":"https://api.github.com/repos/birdbrained/collections-service/tags","blobs_url":"https://api.github.com/repos/birdbrained/collections-service/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/birdbrained/collections-service/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/birdbrained/collections-service/git/refs{/sha}","trees_url":"https://api.github.com/repos/birdbrained/collections-service/git/trees{/sha}","statuses_url":"https://api.github.com/repos/birdbrained/collections-service/statuses/{sha}","languages_url":"https://api.github.com/repos/birdbrained/collections-service/languages","stargazers_url":"https://api.github.com/repos/birdbrained/collections-service/stargazers","contributors_url":"https://api.github.com/repos/birdbrained/collections-service/contributors","subscribers_url":"https://api.github.com/repos/birdbrained/collections-service/subscribers","subscription_url":"https://api.github.com/repos/birdbrained/collections-service/subscription","commits_url":"https://api.github.com/repos/birdbrained/collections-service/commits{/sha}","git_commits_url":"https://api.github.com/repos/birdbrained/collections-service/git/commits{/sha}","comments_url":"https://api.github.com/repos/birdbrained/collections-service/comments{/number}","issue_comment_url":"https://api.github.com/repos/birdbrained/collections-service/issues/comments{/number}","contents_url":"https://api.github.com/repos/birdbrained/collections-service/contents/{+path}","compare_url":"https://api.github.com/repos/birdbrained/collections-service/compare/{base}...{head}","merges_url":"https://api.github.com/repos/birdbrained/collections-service/merges","archive_url":"https://api.github.com/repos/birdbrained/collections-service/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/birdbrained/collections-service/downloads","issues_url":"https://api.github.com/repos/birdbrained/collections-service/issues{/number}","pulls_url":"https://api.github.com/repos/birdbrained/collections-service/pulls{/number}","milestones_url":"https://api.github.com/repos/birdbrained/collections-service/milestones{/number}","notifications_url":"https://api.github.com/repos/birdbrained/collections-service/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/birdbrained/collections-service/labels{/name}","releases_url":"https://api.github.com/repos/birdbrained/collections-service/releases{/id}","deployments_url":"https://api.github.com/repos/birdbrained/collections-service/deployments","created_at":"2017-06-30T23:23:41Z","updated_at":"2017-08-23T19:25:45Z","pushed_at":"2017-10-04T18:26:20Z","git_url":"git://github.com/birdbrained/collections-service.git","ssh_url":"git@github.com:birdbrained/collections-service.git","clone_url":"https://github.com/birdbrained/collections-service.git","svn_url":"https://github.com/birdbrained/collections-service","homepage":null,"size":4032,"stargazers_count":0,"watchers_count":0,"language":"Python","has_issues":false,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":1,"mirror_url":null,"open_issues_count":0,"forks":1,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"cos-labs:develop","ref":"develop","sha":"532bfdc3771b268dd9b2cbeed064af3d47fb7c3d","user":{"login":"cos-labs","id":21039091,"avatar_url":"https://avatars1.githubusercontent.com/u/21039091?v=4","gravatar_id":"","url":"https://api.github.com/users/cos-labs","html_url":"https://github.com/cos-labs","followers_url":"https://api.github.com/users/cos-labs/followers","following_url":"https://api.github.com/users/cos-labs/following{/other_user}","gists_url":"https://api.github.com/users/cos-labs/gists{/gist_id}","starred_url":"https://api.github.com/users/cos-labs/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/cos-labs/subscriptions","organizations_url":"https://api.github.com/users/cos-labs/orgs","repos_url":"https://api.github.com/users/cos-labs/repos","events_url":"https://api.github.com/users/cos-labs/events{/privacy}","received_events_url":"https://api.github.com/users/cos-labs/received_events","type":"Organization","site_admin":false},"repo":{"id":95930444,"name":"collections-service","full_name":"cos-labs/collections-service","owner":{"login":"cos-labs","id":21039091,"avatar_url":"https://avatars1.githubusercontent.com/u/21039091?v=4","gravatar_id":"","url":"https://api.github.com/users/cos-labs","html_url":"https://github.com/cos-labs","followers_url":"https://api.github.com/users/cos-labs/followers","following_url":"https://api.github.com/users/cos-labs/following{/other_user}","gists_url":"https://api.github.com/users/cos-labs/gists{/gist_id}","starred_url":"https://api.github.com/users/cos-labs/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/cos-labs/subscriptions","organizations_url":"https://api.github.com/users/cos-labs/orgs","repos_url":"https://api.github.com/users/cos-labs/repos","events_url":"https://api.github.com/users/cos-labs/events{/privacy}","received_events_url":"https://api.github.com/users/cos-labs/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/cos-labs/collections-service","description":null,"fork":false,"url":"https://api.github.com/repos/cos-labs/collections-service","forks_url":"https://api.github.com/repos/cos-labs/collections-service/forks","keys_url":"https://api.github.com/repos/cos-labs/collections-service/keys{/key_id}","collaborators_url":"https://api.github.com/repos/cos-labs/collections-service/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/cos-labs/collections-service/teams","hooks_url":"https://api.github.com/repos/cos-labs/collections-service/hooks","issue_events_url":"https://api.github.com/repos/cos-labs/collections-service/issues/events{/number}","events_url":"https://api.github.com/repos/cos-labs/collections-service/events","assignees_url":"https://api.github.com/repos/cos-labs/collections-service/assignees{/user}","branches_url":"https://api.github.com/repos/cos-labs/collections-service/branches{/branch}","tags_url":"https://api.github.com/repos/cos-labs/collections-service/tags","blobs_url":"https://api.github.com/repos/cos-labs/collections-service/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/cos-labs/collections-service/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/cos-labs/collections-service/git/refs{/sha}","trees_url":"https://api.github.com/repos/cos-labs/collections-service/git/trees{/sha}","statuses_url":"https://api.github.com/repos/cos-labs/collections-service/statuses/{sha}","languages_url":"https://api.github.com/repos/cos-labs/collections-service/languages","stargazers_url":"https://api.github.com/repos/cos-labs/collections-service/stargazers","contributors_url":"https://api.github.com/repos/cos-labs/collections-service/contributors","subscribers_url":"https://api.github.com/repos/cos-labs/collections-service/subscribers","subscription_url":"https://api.github.com/repos/cos-labs/collections-service/subscription","commits_url":"https://api.github.com/repos/cos-labs/collections-service/commits{/sha}","git_commits_url":"https://api.github.com/repos/cos-labs/collections-service/git/commits{/sha}","comments_url":"https://api.github.com/repos/cos-labs/collections-service/comments{/number}","issue_comment_url":"https://api.github.com/repos/cos-labs/collections-service/issues/comments{/number}","contents_url":"https://api.github.com/repos/cos-labs/collections-service/contents/{+path}","compare_url":"https://api.github.com/repos/cos-labs/collections-service/compare/{base}...{head}","merges_url":"https://api.github.com/repos/cos-labs/collections-service/merges","archive_url":"https://api.github.com/repos/cos-labs/collections-service/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/cos-labs/collections-service/downloads","issues_url":"https://api.github.com/repos/cos-labs/collections-service/issues{/number}","pulls_url":"https://api.github.com/repos/cos-labs/collections-service/pulls{/number}","milestones_url":"https://api.github.com/repos/cos-labs/collections-service/milestones{/number}","notifications_url":"https://api.github.com/repos/cos-labs/collections-service/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/cos-labs/collections-service/labels{/name}","releases_url":"https://api.github.com/repos/cos-labs/collections-service/releases{/id}","deployments_url":"https://api.github.com/repos/cos-labs/collections-service/deployments","created_at":"2017-06-30T23:22:34Z","updated_at":"2017-08-15T17:53:28Z","pushed_at":"2017-10-04T18:26:21Z","git_url":"git://github.com/cos-labs/collections-service.git","ssh_url":"git@github.com:cos-labs/collections-service.git","clone_url":"https://github.com/cos-labs/collections-service.git","svn_url":"https://github.com/cos-labs/collections-service","homepage":null,"size":3990,"stargazers_count":1,"watchers_count":1,"language":"Python","has_issues":true,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":true,"forks_count":4,"mirror_url":null,"open_issues_count":1,"forks":4,"open_issues":1,"watchers":1,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/cos-labs/collections-service/pulls/50"},"html":{"href":"https://github.com/cos-labs/collections-service/pull/50"},"issue":{"href":"https://api.github.com/repos/cos-labs/collections-service/issues/50"},"comments":{"href":"https://api.github.com/repos/cos-labs/collections-service/issues/50/comments"},"review_comments":{"href":"https://api.github.com/repos/cos-labs/collections-service/pulls/50/comments"},"review_comment":{"href":"https://api.github.com/repos/cos-labs/collections-service/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/cos-labs/collections-service/pulls/50/commits"},"statuses":{"href":"https://api.github.com/repos/cos-labs/collections-service/statuses/d3577e4975c7ab9029dfb44009fb7d221a79a5a4"}},"author_association":"COLLABORATOR"}}
{"actor":{"display_login":"cameronblandford"}}