> If you don't mind me asking, why do use ModelForm and not the ORM
> directly? I'm just curious as using just a model (possibly wirh model
> validation) seems like easies approach.
>
> Cheers
>
> Jirka
Hi Jirka!
The idea behind the modelform is bring an intuitive way to the admin
of the site (a non django-developer) for doing the import of several
files. If with the ORM i can do something similar, it will be great!
There's something i can read to get into it?
> 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!
--
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