SHARE
TWEET

Untitled

a guest Aug 25th, 2019 65 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. from api import views
  2. from api.converters import DateConverter
  3.  
  4. register_converter(DateConverter, 'yyyy-mm-dd')
  5.  
  6. router = routers.DefaultRouter()
  7. router.register(r"transfers/<yyyy-mm-dd:date>", views.TransfersDateViewSet,
  8.                 basename="transfers")
  9. router.register(r"transfers", views.TransfersViewSet)
  10.  
  11. class DateConverter:
  12.     regex = r'\d{4}-\d{2}-\d{2}'
  13.  
  14.     def to_python(self, value):
  15.         return datetime.strptime(value, "%Y-%m-%d")
  16.  
  17.     def to_url(self, value):
  18.         return value.strftime("%Y-%m-%d")
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top