Skip to content

Instantly share code, notes, and snippets.

@sky-code
Created April 25, 2018 21:57
Show Gist options
  • Select an option

  • Save sky-code/d0f6ed877770d30b9fd325fba2e59437 to your computer and use it in GitHub Desktop.

Select an option

Save sky-code/d0f6ed877770d30b9fd325fba2e59437 to your computer and use it in GitHub Desktop.
django bson ObjectID url path validator
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