-
-
Notifications
You must be signed in to change notification settings - Fork 6.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add format
argument to UUIDField
#2788
Conversation
LGTM |
Seconded here. |
- `'hex'` - The compact hex representation of the UUID, not including hyphens | ||
- `'int'` - A 128 bit integer representation of the UUID. | ||
- `'urn'` - RFC 4122 URN representation of the UUID | ||
The `to_internal_value` will accept any of the string formats of a UUID unless the `format` is `'int'`, when it will accept a |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks truncated.
To allow serializations to control the representation format of a UUID value
+1 |
if self.uuid_format == 'hex_verbose': | ||
return str(value) | ||
else: | ||
return getattr(value, self.uuid_format) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not entirely sure what potential problem you foresee here.
Which int
case? The case where format is 'int'
, or the case where an int
has somehow been passed to to_representation
? None of the other fields check too rigorously for an incorrect type being passed to to_representation
.
One query worth having a quikc think about but otherwise reckon I'm happy for this to go in. |
- `'hex_verbose'` - The cannoncical hex representation, including hyphens | ||
- `'hex'` - The compact hex representation of the UUID, not including hyphens | ||
- `'int'` - A 128 bit integer representation of the UUID. | ||
- `'urn'` - RFC 4122 URN representation of the UUID |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could we have examples here?
Okay one last comment regarding the docs. Otherwise good after that! :) |
Closing this in favor of #3000. |
format
argument to UUIDField
@ovangle thanks for the PR. |
That's OK. I seem to have missed a couple of emails telling me to follow up on it. Sorry about that. |
@ovangle no problem at all |
To allow serializations to control the representation format of a
UUID value