Created
October 14, 2019 10:33
-
-
Save nwjlyons/88d763f27b137ccb3f6638e59ac5bc58 to your computer and use it in GitHub Desktop.
Django Date Path Converter
This file contains 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 datetime import datetime, date | |
class DateConverter: | |
regex = '[0-9]{4}-[0-9]{2}-[0-9]{2}' | |
def to_python(self, value: str): | |
return datetime.strptime(value, '%Y-%m-%d').date() | |
def to_url(self, value: date): | |
return value.strftime('%Y-%m-%d') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Date object will be passed to view function/method.