johnpaulett / django-durationfield Goto Github PK
View Code? Open in Web Editor NEWTemporary reusable Django application for adding a DurationField, until Django issue #2443 is resolved.
Home Page: http://django-durationfield.readthedocs.org
Temporary reusable Django application for adding a DurationField, until Django issue #2443 is resolved.
Home Page: http://django-durationfield.readthedocs.org
I would like to translate output of time duration to some languages (mainly my native Turkish). But couldn't see a locale folder. would you consider this?
It appears that as of 1.8, Django has a native DurationField model. I tried just replacing the fields on my model with the native Django version, but when I apply the migration it says:
column "the_column_with_the_durationfield" cannot be cast automatically to type interval
HINT: Specify a USING expression to perform the conversion
How can I go about migrating to the natively supported field? And what is the path forward for this project now that it's supported natively by Django?
Hello John,
"six" seems dedicated for python 3.
Is django-durationfield compatible with python 2.7 ? because it asks for six that is not available for 2.7...
Regards,
Laurent
I have made a RAW query in my view, so I'm showing the results at the template but the durationfield is shown as a timestamp, as it is the way its saved in the database.
What is the best approach to solve that? An easy way to make a template filter?
Result:
Name: xx
Duration: 135360000
Desired Result:
Name: xx
Duration: 0:02:15.360000
Many thanks
The duration field is providing the good reference to add the duration. Could you let me know how can I test and run the server with this to see if the code is working?
I am moving a project over to Django 1.7 and noticed that the DurationField for the model gets not created in the database.
The migrations itself appear to handle it (and renames to it), but it does not appear in the actual database (PostgreSQL).
I suspect this might be an issue in Django itself, but wanted to raise it here first.
From the initial migration:
('runtime', durationfield.db.models.fields.duration.DurationField(help_text=u'Format: HH:MM:SS', null=True, verbose_name=u'Playtime')),
Let me know, if I should provide a test case, but maybe it is a known issue already.
Also note, that I was using SQLite initially (where it worked), but now switched to PostgreSQL (with a new DB).
Hi,
I noticed your project no longer supports Django 1.1. The following error occurs:
durationfield/forms/widgets.py", line 10, in <module>
from durationfield.utils import compat as formats
ImportError: cannot import name compat
So… a while back I created an experimental branch ( poswald/django-durationfield@exp-timedelta-internal ) that would use the python timedelta type as the native type returned to code calling this field. I figured that it might be nicer to use the native python type.
It turns out that the python timedelta
is type is not a 100% slam dunk choice. The way it stores time as days, seconds, microseconds is a bit unconventional and the input/output methods available are somewhat limited.
That being said, it's the version I use most often and a few people have forked it. I got to thinking on how to reconcile this and I was considering perhaps it should be an alternate field or widget in the project, not just a fork. I'd like to know if anyone has any thoughts about this.
I'm opening this issue here rather than on my own branch since as the original version, more people watch yours.
Create a template tag that format the timedelta to a friendly display. Right now if you call the string representation for the duration field you get:
>>> my_object = MyObject.objects.create(duration='0:03:58.16')
>>> my_object.duration
0:03:58.000016
For template formatting, something like:
{{ my_object.duration|duration }}
That outputs:
0:03:58
or even:
3:58
Something similar to what's going on here:
(Thinking about machines and importing data)
There is an standard about how to express durations, ISO8601 [1], it would be interesting to allow this format as input, although maintain as output both, ISO8601 and the more readable one (current).
I would have expected to see validation errors, in case of input like "invalid", but it gets handled as / converted to 0.
This is most likely, because str_to_timedelta('invalid')
does not raise an exception.
Also, "86400" should either gets handled as seconds (resulting in one day), or also raise an exception / validation error,
Hi,
durationfield.forms.fields.py is missing the following import.
from durationfield.utils.timestring import to_timedelta
Regards
Adi
Just wondering if anyone knows if it's lethargy or strategy that caused this to be overlooked for 1.3...
When migrating from previous implementations of DurationField I found my json data dump fields to be encapsulated by quotes. When loading the data into the new schema this causes the value parameter to be passed as unicode. I put in the following fix:
def get_db_prep_save(self, value):
if value is None:
return None # db NULL
if isinstance(value, int) or isinstance(value, long):
value = timedelta(microseconds=value)
elif isinstance(value,unicode) or isinstance(value, str):
value = timedelta(microseconds=int(value))
return value.days * 24 * 3600 * 1000000 + value.seconds * 1000000 + value.microseconds
duration.py uses 1.5-only features:
Django version 3.0 does not support django.utils.six package. It is removed.
Environment:
Python==3.8
Django==3.2
django-durationfield==0.5.5
Error:
from durationfield.db.models.fields.duration import DurationField
File "/env/lib/python3.8/site-packages/durationfield/db/models/fields/duration.py", line 5, in <module>
from django.utils import six
ImportError: cannot import name 'six' from 'django.utils' (/env/lib/python3.8/site-packages/django/utils/__init__.py)
When I try to save the a time in the following format:
00:04
I would expect that to be saved as 4 seconds, correct? When it saves, it saves as 4 minutes. So, when I go back edit the field, it prompts me with:
0:04:00
Which is incorrect.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.