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.

Revisions

  1. sky-code created this gist Apr 25, 2018.
    13 changes: 13 additions & 0 deletions converters.py
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,13 @@
    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