Coder Social home page Coder Social logo

johnpaulett / django-durationfield Goto Github PK

View Code? Open in Web Editor NEW
67.0 67.0 24.0 91 KB

Temporary reusable Django application for adding a DurationField, until Django issue #2443 is resolved.

Home Page: http://django-durationfield.readthedocs.org

Python 99.24% Shell 0.31% Makefile 0.45%

django-durationfield's People

Contributors

bastbnl avatar glibersat avatar johnpaulett avatar linevych avatar poswald avatar troygrosfield avatar winhamwr avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

django-durationfield's Issues

localization?

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?

Django 1.8 supports DurationField natively, but there's no easy way to migrate

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?

Error when "from django.utils import six"

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

Raw query

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

manage.py file and running the server

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?

DurationField is not created in the database (Django 1.7)

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).

Django 1.1 is not supported

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

Fate of the 'poswald/exp-timedelta-internal' branch

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.

Add Template Tags for time display

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:

Does not raise ValueError for input like "invalid"

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,

missing import

Hi,

durationfield.forms.fields.py is missing the following import.

from durationfield.utils.timestring import to_timedelta

Regards
Adi

get_db_prep_save should attempt conversion from strings

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

Does not support Django version >=3.0

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)

Incorrectly saving seconds as minutes

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.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.