> > On 27/10/2010, Daniel Roseman <dan...@roseman.org.uk> wrote:
>
> > > You're setting the values on `self` in the form's save method. In
> > > other words, you're setting them on the *form*, not the instance. You
> > > should be setting them on `form_instance`.
>
> > > Also, don't convert the decimals to float. Decimal accepts a string
> > > value, and converting to float will just introduce possible floating-
> > > point precision errors.
> > > --
> > > DR.
>
> Thanks Daniel!
>
> I do some changes:
>
> Forms.py:
>
> def save(self, commit=True, *args, **kwargs):
> form_input = super(DataInput, self).save(commit=False, *args,
> **kwargs)
> form_input.place = self.cleaned_data['place']
> form_input.file = self.cleaned_data['file']
> records = csv.reader(form_input.file)
> for line in records:
> self.time = datetime.strptime(line[1], "%m/%d/%y %H:%M:
> %S")
> self.data_1 = line[2]
> self.data_2 = line[3]
> self.data_3 = line[4]
> form_input.save()
>
> But i'm still get the same IntegrityError. The csv file is fine, so i
> don't know why is null.
>
> Regards!
Shame on me!
I forgot to make some changes inside the for loop.
So now it is:
def save(self, commit=True, *args, **kwargs):
form_input = super(DataInput, self).save(commit=False, *args,
**kwargs)
form_input.place = self.cleaned_data['place']
form_input.file = self.cleaned_data['file']
records = csv.reader(form_input.file)
for line in records:
form_input.time = datetime.strptime(line[1], "%m/%d/%y %H:
%M:
%S")
form_input.data_1 = line[2]
form_input.data_2 = line[3]
form_input.data_3 = line[4]
form_input.save()
Buuuuut, i've got a new error message! an attribute error: 'NoneType'
object has no attribute 'save'.
What can it be?
--
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.
No comments:
Post a Comment