{"action":"created","comment":{"url":"https://api.github.com/repos/tomchristie/django-rest-framework/pulls/comments/28602539","id":28602539,"diff_hunk":"@@ -639,20 +639,37 @@ def __init__(self, **kwargs):\n \n \n class UUIDField(Field):\n+    valid_formats = ('hex_verbose', 'hex', 'int', 'urn')\n+\n     default_error_messages = {\n         'invalid': _('\"{value}\" is not a valid UUID.'),\n     }\n \n+    def __init__(self, **kwargs):\n+        self.uuid_format = kwargs.pop('format', 'hex_verbose')\n+        if self.uuid_format not in self.valid_formats:\n+            raise ValueError(\n+                'Invalid format for uuid representation. '\n+                'Must be one of \"{0}\"'.format('\", \"'.join(self.valid_formats))\n+            )\n+        super(UUIDField, self).__init__(**kwargs)\n+\n     def to_internal_value(self, data):\n         if not isinstance(data, uuid.UUID):\n             try:\n-                return uuid.UUID(data)\n+                if isinstance(data, six.integer_types):\n+                    return uuid.UUID(int=data)\n+                else:\n+                    return uuid.UUID(hex=data)\n             except (ValueError, TypeError):\n                 self.fail('invalid', value=data)\n         return data\n \n     def to_representation(self, value):\n-        return str(value)\n+        if self.uuid_format == 'hex_verbose':\n+            return str(value)\n+        else:\n+            return getattr(value, self.uuid_format)","path":"rest_framework/fields.py","position":36,"original_position":36,"commit_id":"236b73107217b8207f0057d86b41bb899678a07f","original_commit_id":"236b73107217b8207f0057d86b41bb899678a07f","user":{"login":"tomchristie","id":647359,"avatar_url":"https://avatars.githubusercontent.com/u/647359?v=3","gravatar_id":"","url":"https://api.github.com/users/tomchristie","html_url":"https://github.com/tomchristie","followers_url":"https://api.github.com/users/tomchristie/followers","following_url":"https://api.github.com/users/tomchristie/following{/other_user}","gists_url":"https://api.github.com/users/tomchristie/gists{/gist_id}","starred_url":"https://api.github.com/users/tomchristie/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/tomchristie/subscriptions","organizations_url":"https://api.github.com/users/tomchristie/orgs","repos_url":"https://api.github.com/users/tomchristie/repos","events_url":"https://api.github.com/users/tomchristie/events{/privacy}","received_events_url":"https://api.github.com/users/tomchristie/received_events","type":"User","site_admin":false},"body":"Are we always going to be handling the int case correctly here? Any cases where that can just be an int, rather than a UUID instance?","created_at":"2015-04-17T15:12:50Z","updated_at":"2015-04-17T15:12:50Z","html_url":"https://github.com/tomchristie/django-rest-framework/pull/2788#discussion_r28602539","pull_request_url":"https://api.github.com/repos/tomchristie/django-rest-framework/pulls/2788","_links":{"self":{"href":"https://api.github.com/repos/tomchristie/django-rest-framework/pulls/comments/28602539"},"html":{"href":"https://github.com/tomchristie/django-rest-framework/pull/2788#discussion_r28602539"},"pull_request":{"href":"https://api.github.com/repos/tomchristie/django-rest-framework/pulls/2788"}}},"pull_request":{"url":"https://api.github.com/repos/tomchristie/django-rest-framework/pulls/2788","id":32482317,"html_url":"https://github.com/tomchristie/django-rest-framework/pull/2788","diff_url":"https://github.com/tomchristie/django-rest-framework/pull/2788.diff","patch_url":"https://github.com/tomchristie/django-rest-framework/pull/2788.patch","issue_url":"https://api.github.com/repos/tomchristie/django-rest-framework/issues/2788","number":2788,"state":"open","locked":false,"title":"Add 'format' argument to UUIDField","user":{"login":"ovangle","id":1032814,"avatar_url":"https://avatars.githubusercontent.com/u/1032814?v=3","gravatar_id":"","url":"https://api.github.com/users/ovangle","html_url":"https://github.com/ovangle","followers_url":"https://api.github.com/users/ovangle/followers","following_url":"https://api.github.com/users/ovangle/following{/other_user}","gists_url":"https://api.github.com/users/ovangle/gists{/gist_id}","starred_url":"https://api.github.com/users/ovangle/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ovangle/subscriptions","organizations_url":"https://api.github.com/users/ovangle/orgs","repos_url":"https://api.github.com/users/ovangle/repos","events_url":"https://api.github.com/users/ovangle/events{/privacy}","received_events_url":"https://api.github.com/users/ovangle/received_events","type":"User","site_admin":false},"body":"To allow serializations to control the representation format of a\r\nUUID value","created_at":"2015-04-02T04:27:51Z","updated_at":"2015-04-17T15:12:50Z","closed_at":null,"merged_at":null,"merge_commit_sha":"43344f66d2a25b90504015773409d2482bbd8760","assignee":null,"milestone":{"url":"https://api.github.com/repos/tomchristie/django-rest-framework/milestones/21","html_url":"https://github.com/tomchristie/django-rest-framework/milestones/3.1.2%20Release","labels_url":"https://api.github.com/repos/tomchristie/django-rest-framework/milestones/21/labels","id":1023197,"number":21,"title":"3.1.2 Release","description":"","creator":{"login":"tomchristie","id":647359,"avatar_url":"https://avatars.githubusercontent.com/u/647359?v=3","gravatar_id":"","url":"https://api.github.com/users/tomchristie","html_url":"https://github.com/tomchristie","followers_url":"https://api.github.com/users/tomchristie/followers","following_url":"https://api.github.com/users/tomchristie/following{/other_user}","gists_url":"https://api.github.com/users/tomchristie/gists{/gist_id}","starred_url":"https://api.github.com/users/tomchristie/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/tomchristie/subscriptions","organizations_url":"https://api.github.com/users/tomchristie/orgs","repos_url":"https://api.github.com/users/tomchristie/repos","events_url":"https://api.github.com/users/tomchristie/events{/privacy}","received_events_url":"https://api.github.com/users/tomchristie/received_events","type":"User","site_admin":false},"open_issues":6,"closed_issues":6,"state":"open","created_at":"2015-03-16T12:10:40Z","updated_at":"2015-04-08T21:11:40Z","due_on":null,"closed_at":null},"commits_url":"https://api.github.com/repos/tomchristie/django-rest-framework/pulls/2788/commits","review_comments_url":"https://api.github.com/repos/tomchristie/django-rest-framework/pulls/2788/comments","review_comment_url":"https://api.github.com/repos/tomchristie/django-rest-framework/pulls/comments{/number}","comments_url":"https://api.github.com/repos/tomchristie/django-rest-framework/issues/2788/comments","statuses_url":"https://api.github.com/repos/tomchristie/django-rest-framework/statuses/236b73107217b8207f0057d86b41bb899678a07f","head":{"label":"ovangle:uuid_format2","ref":"uuid_format2","sha":"236b73107217b8207f0057d86b41bb899678a07f","user":{"login":"ovangle","id":1032814,"avatar_url":"https://avatars.githubusercontent.com/u/1032814?v=3","gravatar_id":"","url":"https://api.github.com/users/ovangle","html_url":"https://github.com/ovangle","followers_url":"https://api.github.com/users/ovangle/followers","following_url":"https://api.github.com/users/ovangle/following{/other_user}","gists_url":"https://api.github.com/users/ovangle/gists{/gist_id}","starred_url":"https://api.github.com/users/ovangle/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ovangle/subscriptions","organizations_url":"https://api.github.com/users/ovangle/orgs","repos_url":"https://api.github.com/users/ovangle/repos","events_url":"https://api.github.com/users/ovangle/events{/privacy}","received_events_url":"https://api.github.com/users/ovangle/received_events","type":"User","site_admin":false},"repo":{"id":32561095,"name":"django-rest-framework","full_name":"ovangle/django-rest-framework","owner":{"login":"ovangle","id":1032814,"avatar_url":"https://avatars.githubusercontent.com/u/1032814?v=3","gravatar_id":"","url":"https://api.github.com/users/ovangle","html_url":"https://github.com/ovangle","followers_url":"https://api.github.com/users/ovangle/followers","following_url":"https://api.github.com/users/ovangle/following{/other_user}","gists_url":"https://api.github.com/users/ovangle/gists{/gist_id}","starred_url":"https://api.github.com/users/ovangle/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ovangle/subscriptions","organizations_url":"https://api.github.com/users/ovangle/orgs","repos_url":"https://api.github.com/users/ovangle/repos","events_url":"https://api.github.com/users/ovangle/events{/privacy}","received_events_url":"https://api.github.com/users/ovangle/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/ovangle/django-rest-framework","description":"Web APIs for Django.","fork":true,"url":"https://api.github.com/repos/ovangle/django-rest-framework","forks_url":"https://api.github.com/repos/ovangle/django-rest-framework/forks","keys_url":"https://api.github.com/repos/ovangle/django-rest-framework/keys{/key_id}","collaborators_url":"https://api.github.com/repos/ovangle/django-rest-framework/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/ovangle/django-rest-framework/teams","hooks_url":"https://api.github.com/repos/ovangle/django-rest-framework/hooks","issue_events_url":"https://api.github.com/repos/ovangle/django-rest-framework/issues/events{/number}","events_url":"https://api.github.com/repos/ovangle/django-rest-framework/events","assignees_url":"https://api.github.com/repos/ovangle/django-rest-framework/assignees{/user}","branches_url":"https://api.github.com/repos/ovangle/django-rest-framework/branches{/branch}","tags_url":"https://api.github.com/repos/ovangle/django-rest-framework/tags","blobs_url":"https://api.github.com/repos/ovangle/django-rest-framework/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/ovangle/django-rest-framework/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/ovangle/django-rest-framework/git/refs{/sha}","trees_url":"https://api.github.com/repos/ovangle/django-rest-framework/git/trees{/sha}","statuses_url":"https://api.github.com/repos/ovangle/django-rest-framework/statuses/{sha}","languages_url":"https://api.github.com/repos/ovangle/django-rest-framework/languages","stargazers_url":"https://api.github.com/repos/ovangle/django-rest-framework/stargazers","contributors_url":"https://api.github.com/repos/ovangle/django-rest-framework/contributors","subscribers_url":"https://api.github.com/repos/ovangle/django-rest-framework/subscribers","subscription_url":"https://api.github.com/repos/ovangle/django-rest-framework/subscription","commits_url":"https://api.github.com/repos/ovangle/django-rest-framework/commits{/sha}","git_commits_url":"https://api.github.com/repos/ovangle/django-rest-framework/git/commits{/sha}","comments_url":"https://api.github.com/repos/ovangle/django-rest-framework/comments{/number}","issue_comment_url":"https://api.github.com/repos/ovangle/django-rest-framework/issues/comments{/number}","contents_url":"https://api.github.com/repos/ovangle/django-rest-framework/contents/{+path}","compare_url":"https://api.github.com/repos/ovangle/django-rest-framework/compare/{base}...{head}","merges_url":"https://api.github.com/repos/ovangle/django-rest-framework/merges","archive_url":"https://api.github.com/repos/ovangle/django-rest-framework/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/ovangle/django-rest-framework/downloads","issues_url":"https://api.github.com/repos/ovangle/django-rest-framework/issues{/number}","pulls_url":"https://api.github.com/repos/ovangle/django-rest-framework/pulls{/number}","milestones_url":"https://api.github.com/repos/ovangle/django-rest-framework/milestones{/number}","notifications_url":"https://api.github.com/repos/ovangle/django-rest-framework/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/ovangle/django-rest-framework/labels{/name}","releases_url":"https://api.github.com/repos/ovangle/django-rest-framework/releases{/id}","created_at":"2015-03-20T03:46:45Z","updated_at":"2015-03-26T07:27:51Z","pushed_at":"2015-04-12T12:08:00Z","git_url":"git://github.com/ovangle/django-rest-framework.git","ssh_url":"git@github.com:ovangle/django-rest-framework.git","clone_url":"https://github.com/ovangle/django-rest-framework.git","svn_url":"https://github.com/ovangle/django-rest-framework","homepage":"www.django-rest-framework.org","size":17017,"stargazers_count":0,"watchers_count":0,"language":"Python","has_issues":false,"has_downloads":true,"has_wiki":false,"has_pages":true,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"tomchristie:master","ref":"master","sha":"970bfe16ecb888ac16fca08591e8d0ff5f1e9e7e","user":{"login":"tomchristie","id":647359,"avatar_url":"https://avatars.githubusercontent.com/u/647359?v=3","gravatar_id":"","url":"https://api.github.com/users/tomchristie","html_url":"https://github.com/tomchristie","followers_url":"https://api.github.com/users/tomchristie/followers","following_url":"https://api.github.com/users/tomchristie/following{/other_user}","gists_url":"https://api.github.com/users/tomchristie/gists{/gist_id}","starred_url":"https://api.github.com/users/tomchristie/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/tomchristie/subscriptions","organizations_url":"https://api.github.com/users/tomchristie/orgs","repos_url":"https://api.github.com/users/tomchristie/repos","events_url":"https://api.github.com/users/tomchristie/events{/privacy}","received_events_url":"https://api.github.com/users/tomchristie/received_events","type":"User","site_admin":false},"repo":{"id":1431547,"name":"django-rest-framework","full_name":"tomchristie/django-rest-framework","owner":{"login":"tomchristie","id":647359,"avatar_url":"https://avatars.githubusercontent.com/u/647359?v=3","gravatar_id":"","url":"https://api.github.com/users/tomchristie","html_url":"https://github.com/tomchristie","followers_url":"https://api.github.com/users/tomchristie/followers","following_url":"https://api.github.com/users/tomchristie/following{/other_user}","gists_url":"https://api.github.com/users/tomchristie/gists{/gist_id}","starred_url":"https://api.github.com/users/tomchristie/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/tomchristie/subscriptions","organizations_url":"https://api.github.com/users/tomchristie/orgs","repos_url":"https://api.github.com/users/tomchristie/repos","events_url":"https://api.github.com/users/tomchristie/events{/privacy}","received_events_url":"https://api.github.com/users/tomchristie/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/tomchristie/django-rest-framework","description":"Web APIs for Django.","fork":false,"url":"https://api.github.com/repos/tomchristie/django-rest-framework","forks_url":"https://api.github.com/repos/tomchristie/django-rest-framework/forks","keys_url":"https://api.github.com/repos/tomchristie/django-rest-framework/keys{/key_id}","collaborators_url":"https://api.github.com/repos/tomchristie/django-rest-framework/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/tomchristie/django-rest-framework/teams","hooks_url":"https://api.github.com/repos/tomchristie/django-rest-framework/hooks","issue_events_url":"https://api.github.com/repos/tomchristie/django-rest-framework/issues/events{/number}","events_url":"https://api.github.com/repos/tomchristie/django-rest-framework/events","assignees_url":"https://api.github.com/repos/tomchristie/django-rest-framework/assignees{/user}","branches_url":"https://api.github.com/repos/tomchristie/django-rest-framework/branches{/branch}","tags_url":"https://api.github.com/repos/tomchristie/django-rest-framework/tags","blobs_url":"https://api.github.com/repos/tomchristie/django-rest-framework/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/tomchristie/django-rest-framework/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/tomchristie/django-rest-framework/git/refs{/sha}","trees_url":"https://api.github.com/repos/tomchristie/django-rest-framework/git/trees{/sha}","statuses_url":"https://api.github.com/repos/tomchristie/django-rest-framework/statuses/{sha}","languages_url":"https://api.github.com/repos/tomchristie/django-rest-framework/languages","stargazers_url":"https://api.github.com/repos/tomchristie/django-rest-framework/stargazers","contributors_url":"https://api.github.com/repos/tomchristie/django-rest-framework/contributors","subscribers_url":"https://api.github.com/repos/tomchristie/django-rest-framework/subscribers","subscription_url":"https://api.github.com/repos/tomchristie/django-rest-framework/subscription","commits_url":"https://api.github.com/repos/tomchristie/django-rest-framework/commits{/sha}","git_commits_url":"https://api.github.com/repos/tomchristie/django-rest-framework/git/commits{/sha}","comments_url":"https://api.github.com/repos/tomchristie/django-rest-framework/comments{/number}","issue_comment_url":"https://api.github.com/repos/tomchristie/django-rest-framework/issues/comments{/number}","contents_url":"https://api.github.com/repos/tomchristie/django-rest-framework/contents/{+path}","compare_url":"https://api.github.com/repos/tomchristie/django-rest-framework/compare/{base}...{head}","merges_url":"https://api.github.com/repos/tomchristie/django-rest-framework/merges","archive_url":"https://api.github.com/repos/tomchristie/django-rest-framework/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/tomchristie/django-rest-framework/downloads","issues_url":"https://api.github.com/repos/tomchristie/django-rest-framework/issues{/number}","pulls_url":"https://api.github.com/repos/tomchristie/django-rest-framework/pulls{/number}","milestones_url":"https://api.github.com/repos/tomchristie/django-rest-framework/milestones{/number}","notifications_url":"https://api.github.com/repos/tomchristie/django-rest-framework/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/tomchristie/django-rest-framework/labels{/name}","releases_url":"https://api.github.com/repos/tomchristie/django-rest-framework/releases{/id}","created_at":"2011-03-02T17:13:56Z","updated_at":"2015-04-17T09:51:01Z","pushed_at":"2015-04-16T20:20:44Z","git_url":"git://github.com/tomchristie/django-rest-framework.git","ssh_url":"git@github.com:tomchristie/django-rest-framework.git","clone_url":"https://github.com/tomchristie/django-rest-framework.git","svn_url":"https://github.com/tomchristie/django-rest-framework","homepage":"www.django-rest-framework.org","size":33099,"stargazers_count":3890,"watchers_count":3890,"language":"Python","has_issues":true,"has_downloads":true,"has_wiki":false,"has_pages":true,"forks_count":1207,"mirror_url":null,"open_issues_count":132,"forks":1207,"open_issues":132,"watchers":3890,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/tomchristie/django-rest-framework/pulls/2788"},"html":{"href":"https://github.com/tomchristie/django-rest-framework/pull/2788"},"issue":{"href":"https://api.github.com/repos/tomchristie/django-rest-framework/issues/2788"},"comments":{"href":"https://api.github.com/repos/tomchristie/django-rest-framework/issues/2788/comments"},"review_comments":{"href":"https://api.github.com/repos/tomchristie/django-rest-framework/pulls/2788/comments"},"review_comment":{"href":"https://api.github.com/repos/tomchristie/django-rest-framework/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/tomchristie/django-rest-framework/pulls/2788/commits"},"statuses":{"href":"https://api.github.com/repos/tomchristie/django-rest-framework/statuses/236b73107217b8207f0057d86b41bb899678a07f"}}}}