Created
April 25, 2018 21:57
-
-
Save sky-code/d0f6ed877770d30b9fd325fba2e59437 to your computer and use it in GitHub Desktop.
django bson ObjectID url path validator
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from bson.objectid import ObjectId | |
| class ObjectIDConverter: | |
| regex = '[0-9A-Fa-f]{24}' | |
| def to_python(self, value): | |
| if ObjectId.is_valid(value): | |
| return value | |
| raise ValueError() | |
| def to_url(self, value): | |
| return value |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment