#2443: Add IntervalField to database models
----------------------------------------------------+-----------------------
Reporter: [EMAIL PROTECTED] | Owner:
adrian
Status: reopened | Component:
Database wrapper
Version: SVN | Resolution:
Keywords: IntervalField interval DurationField | Stage:
Design decision needed
Has_patch: 1 | Needs_docs: 0
Needs_tests: 1 | Needs_better_patch: 1
----------------------------------------------------+-----------------------
Changes (by Marty Alchin <[EMAIL PROTECTED]>):
* keywords: IntervalField interval => IntervalField interval
DurationField
* needs_better_patch: 0 => 1
* has_patch: 0 => 1
* needs_tests: 0 => 1
Comment:
This simple patch adds a !DurationField, which, in my opinion, better
encapsulates the use cases described by anonymous above. Calling it a
duration implies that it's not tied to any specific points in time, but
rather just the passage of a certain amount of time. This makes more sense
for things like the length (duration!) of audio and video content, for
instance.
The patch itself is fairly simple, based on a !FloatField, whose value
represents the number of seconds to be represented. This seems sufficient
for database storage, since all supported backends already support the
equivalent of a !FloatField, while {{{max_digits}}} and
{{{decimal_places}}} allow for a number large enough to represent
{{{timedelta.max}}}, complete with a full set of microseconds. It doesn't
take calendars into account at all, but neither does {{{timedelta}}},
which is also in keeping with the duration concept as opposed to
intervals.
The one problem I have with it so far is that it seems like Django is
relying on backend database connection modules to handle coercion into
Python types, rather than using {{{to_python}}}, so the value isn't
changed into a {{{timedelta}}} unless you manually call {{{.validate()}}}
on the model. This also prevents the validation errors from occurring
properly when editing in the admin. That may be another issue for another
day, however. I've marked the issue as "Patch needs improvement" in case
I'm missing something that would make this happen.
P.S. Pardon the WikiFormatting on the attachment comment. That is, unless
it gets a wiki page, in which case it'll be fine.
--
Ticket URL: <http://code.djangoproject.com/ticket/2443#comment:5>
Django Code <http://code.djangoproject.com/>
The web framework for perfectionists with deadlines
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Django updates" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/django-updates?hl=en
-~----------~----~----~----~------~----~------~--~---