Re: DateTimeField arithmetic problem
On Fri, Dec 4, 2009 at 4:48 AM, Max Battcher <me@worldmaker.net> wrote:
> Continuation wrote:
>> if form.is_valid():
>> object = form.save(commit=False)
>> delta = datetime.timedelta(days=object.days_difference)
>> object.end = object.start + delta
>> object.save()
>>
>> But I got the error:
>> type object 'datetime.datetime' has no attribute 'timedelta'
>
> This sounds like a silly import error... It sounds like you've got
> something like:
>
> from datetime import datetime
>
> Where you really want just:
>
> import datetime
Or, to possibly reduce other code changes:
from datetime import datetime, timedelta
...
delta = timedelta(object.days_difference) # Days is the first
positional argument, can also be float.
>
> (Because datetime.datetime.timedelta doesn't exist, but
> datetime.timedelta does.)
>
> --
> --Max Battcher--
> http://worldmaker.net
>
> --
>
> You received this message because you are subscribed to the Google Groups "Django users" group.
> To post to this group, send email to django-users@googlegroups.com.
> To unsubscribe from this group, send email to django-users+unsubscribe@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
>
>
>
--
You received this message because you are subscribed to the Google Groups "Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to django-users+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.

0 Comments:
Post a Comment
Subscribe to Post Comments [Atom]
<< Home