Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add DurationField. #2481

Closed
tomchristie opened this issue Jan 28, 2015 · 10 comments
Closed

Add DurationField. #2481

tomchristie opened this issue Jan 28, 2015 · 10 comments

Comments

@tomchristie
Copy link
Member

For ModelSerializer classes this should be mapped to by Django 1.8's DurationField.

@tomchristie tomchristie added this to the 3.1.0 Release milestone Jan 28, 2015
@jpadilla
Copy link
Member

Docs: https://docs.djangoproject.com/en/dev/ref/models/fields/#django.db.models.DurationField

What should the representation for this be?

@tomchristie
Copy link
Member Author

Hrm. JSONEncoder will currently handle timedelta as a string representation "123.456788", so options would be:

  • Use string representation.
  • Use timedelta and allow JSONEncoder to handle the final switch.
  • Follow DecimalField and use the string repr by default, but allow the coercion to be switched off.
  • Decide that actually this isn't super worthy of 3.1.0 and push it back along with the range fields.

@jpadilla
Copy link
Member

I personally don't mind pushing this back as well. I like we're already supporting "popular"(or what in my opinion are more seen and useful cases) fields like UUIDField, DictField, and HStoreField.

Perhaps pushing this one back, and work on ArrayField(#2107) for it's current 3.1.0 milestone?

@kevin-brown
Copy link
Member

Decide that actually this isn't super worthy of 3.1.0 and push it back along with the range fields.

👍

@tomchristie tomchristie removed this from the 3.1.0 Release milestone Jan 29, 2015
@tomchristie tomchristie changed the title Support 1.8's DurationField. Add DurationField. Feb 10, 2015
@willstott101
Copy link
Contributor

There's some weird behaviour with this at the moment actually. A ModelSerializer with a (django) DurationField serializes via django.utils.duration.duration_string to days hrs:mins:secs (1 04:00:00) however that's not consistent with the (IMO less useful) current JSON encoder which renders to a decimal of seconds. As for supporting the field I think normalizing the behaviour must surely be the first step. I for one vote for using duration_string for trivial moment.js integration delta_str.replace(' ', '.').

@thedrow
Copy link
Contributor

thedrow commented Apr 25, 2015

Maybe we can provide format options just like we do with the DecimalField.

@tomchristie
Copy link
Member Author

@thedrow Sounds reasonable, yep.

@ghost
Copy link

ghost commented May 25, 2015

Is there any guess on when this might sneak into the codebase? I'm just trying to plan for adding a duration field to one of my models.

@tomchristie
Copy link
Member Author

@rpcastagna Its absolutely not a priority. If anything it might make sense for it to be considered as a third party package first.

@xordoquy xordoquy added this to the 3.1.3 Release milestone Jun 1, 2015
@xordoquy
Copy link
Collaborator

xordoquy commented Jun 1, 2015

Closing this as part of #2989. Feel free to reopen if there is more to be done.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

6 participants