Have tried model.__dict__ and model_to_dict. In both cases it often
returns values as objects instead of string values. For instance, a
date comes back as a list, so does a text field. Then I'll receive an
error like this:

Environment:
Request Method: POST
Request URL: http://127.0.0.1:8000/edit_pet/8/
Django Version: 1.0.2 final
Python Version: 2.5.4

Traceback:
File "C:\Python25\lib\site-packages\django\core\handlers\base.py" in
get_response
  86.                 response = callback(request, *callback_args,
**callback_kwargs)
File "C:\Python25\lib\site-packages\django\contrib\auth\decorators.py"
in __call__
  67.             return self.view_func(request, *args, **kwargs)
File "C:\Python25\lib\site-packages\PetSite\apps\pets\views.py" in
userEditPet
  322.         if form.is_valid():
File "C:\Python25\lib\site-packages\django\forms\forms.py" in is_valid
  120.         return self.is_bound and not bool(self.errors)
File "C:\Python25\lib\site-packages\django\forms\forms.py" in
_get_errors
  111.             self.full_clean()
File "C:\Python25\lib\site-packages\django\forms\forms.py" in
full_clean
  231.                     value = field.clean(value)
File "C:\Python25\lib\site-packages\django\forms\fields.py" in clean
  308.                 return datetime.date(*time.strptime(value,
format)[:3])
File "C:\Python25\lib\_strptime.py" in strptime
  327.     found = format_regex.match(data_string)

Exception Type: TypeError at /edit_pet/8/
Exception Value: expected string or buffer


I did find this ticket http://code.djangoproject.com/ticket/5126 which
I'm going to have a read through in more detail later today. My code
goes like this

values = model_to_dict(instance)
values.update(request.POST)

It then fails on form.is_valid() because it's trying to match a date
string in a date value that is actually a list with one value in it
instead of a date string!




On Feb 16, 9:22 am, Daniel Roseman <dan...@roseman.org.uk> wrote:
> On Feb 15, 10:31 pm, cootetom <coote...@gmail.com> wrote:
>
> > Thanks Javier but I'm having problems with that. I do want to create a
> > dictionary from the model first then override with the POST values.
> > But when I try to make a dictionary from the model I get an 'object is
> > not iterable' error.
>
> You probably want to use model_instance.__dict__ - Python already uses
> a dictionary to hold the underlying instance values in an object.
> --
> 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