I have a model: class MyModel(models.Model): start = models.DateTimeField (auto_now_add=True) days_difference = models.IntegerField() end = models.DateTimeField()
And then I made a form from the model:: class MyForm(forms.ModelForm): Meta: model = MyModel fields = ('days_difference') Basically I take a user input of number of days (say N), and I want to calculate the datetime of N days from now. So I do this in my view: 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' What did I do wrong? I thought datetime.timedelta represents the difference between 2 datetime.datetime instances. object.start is a datetime.datetime instance object.end is also a datetime.datetime instance delta is a datetime.timedelta instance. So shouldn't I be able to add delta to object.start to arrive at object.end? -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.