hi,

sorry. Here's the copy of the traceback.
It's actually a warning, not an error.
I'm using form.save_m2m() because my model includes another m2m field
(I simplified the code for readability), and I'm using
form.save(commit=False) because I don't set the city field using the
city value from request.POST but from further processing of the data.
It still seems to me that save_m2m() tries to save the excluded tag
field.
Thanks for your help.
jul



Traceback:
File "/var/lib/python-support/python2.5/django/core/handlers/base.py"
in get_response
  92.                 response = callback(request, *callback_args,
**callback_kwargs)
File "/home/jul/atable/../atable/resto/views.py" in addRestaurant
  498.                 form.save_m2m()
File "/var/lib/python-support/python2.5/django/forms/models.py" in
save_m2m
  75.                 f.save_form_data(instance, cleaned_data[f.name])
File "/var/lib/python-support/python2.5/django/db/models/fields/
related.py" in save_form_data
  967.         setattr(instance, self.attname, data)
File "/var/lib/python-support/python2.5/django/db/models/fields/
related.py" in __set__
  627.         manager.add(*value)
File "/var/lib/python-support/python2.5/django/db/models/fields/
related.py" in add
  430.                 self._add_items(self.source_col_name,
self.target_col_name, *objs)
File "/var/lib/python-support/python2.5/django/db/models/fields/
related.py" in _add_items
  497.                     [self._pk_val] + list(new_ids))
File "/var/lib/python-support/python2.5/django/db/backends/util.py" in
execute
  19.             return self.cursor.execute(sql, params)
File "/var/lib/python-support/python2.5/django/db/backends/mysql/
base.py" in execute
  84.             return self.cursor.execute(query, args)
File "/var/lib/python-support/python2.5/MySQLdb/cursors.py" in execute
  168.         if not self._defer_warnings: self._warning_check()
File "/var/lib/python-support/python2.5/MySQLdb/cursors.py" in
_warning_check
  82.                     warn(w[-1], self.Warning, 3)
File "/usr/lib/python2.5/warnings.py" in warn
  62.                   globals)
File "/usr/lib/python2.5/warnings.py" in warn_explicit
  102.         raise message

Exception Type: Warning at /restaurant/add/
Exception Value: Truncated incorrect DOUBLE value: 'a'



On Mar 15, 7:15 pm, Daniel Roseman <dan...@roseman.org.uk> wrote:
> On Mar 15, 5:33 pm, jul <juj...@gmail.com> wrote:
>
>
>
> > hi,
>
> > in a ModelForm I replace a field by excluding it and adding a new one
> > with the same name, as shown below in AddRestaurantForm. When saving
> > the form with the code shown below, I get an error in form save_m2m()
> > (Truncated incorrect DOUBLE value), which seems to be due to the
> > function to attempt to save the tag field, while it is excluded.
> > Is the save_m2m() function supposed to save excluded fields?
> > Is there anything wrong in my code?
>
> > Thanks
> > Jul
>
> > (...)
> > new_restaurant = form.save(commit=False)
> > new_restaurant.city = city
> > new_restaurant.save()
>
> > tags =  form.cleaned_data['tag']
> > if(tags!=''): tags=tags.split(',')
> > for t in tags:
> >     tag, created = Tag.objects.get_or_create(name = t.strip())
> >     tag.save()
> >     new_restaurant.tag.add(tag)
>
> > new_restaurant.save()
> > form.save_m2m()
>
> Firstly, it is no use just giving the name of the error. Errors come
> with tracebacks, for good reason: they allow us to see exactly where
> the error is occurring, and the context.
>
> Anyway, in your case, there doesn't seem to be any need to use
> save_m2m. The documentation states:
>   "Calling save_m2m() is only required if you use save(commit=False)"
> In your case, you've already saved the form to get the new_restaurant
> instance, and you're adding tags to that instance with no problem. The
> last two calls, to new_restaurant.save() and form.save_m2m(), are
> unnecessary.
> --
> DR.

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

Reply via email to