Hi!

I've been stuck with this for some days now, and can't find any
answers whatsoever. Please bare with me since I'm a newbie with Python/
Django.

I have this form that's created and populated using
'modelformset_factory'. What it's supposed to do is to
1. show a number of sets so the user can add several at one time. Also
show the added ones, with the possibility to delete them if necessary.
2. Save content. This means insert/update/delete.

Easy enough, ey? But I'm stuck at the error "AttributeError:
'OptionForm' object has no attribute 'cleaned_data'". Strange things
happen here. "OptionForm" doesn't exist for example. I guess Django
adds "Form" by itself, why I don't know.

The full traceback:
Traceback (most recent call last):
  File "C:\Program Files\Python25\Lib\site-packages\django\core\servers
\basehttp.py", line 635, in __call__
    return self.application(environ, start_response)
  File "C:\Program Files\Python25\Lib\site-packages\django\core
\handlers\wsgi.py", line 239, in __call__
    response = self.get_response(request)
  File "C:\Program Files\Python25\Lib\site-packages\django\core
\handlers\base.py", line 128, in get_response
    return self.handle_uncaught_exception(request, resolver, exc_info)
  File "C:\Program Files\Python25\Lib\site-packages\django\core
\handlers\base.py", line 148, in handle_uncaught_exception
    return debug.technical_500_response(request, *exc_info)
  File "C:\Program Files\Python25\Lib\site-packages\django\core
\handlers\base.py", line 86, in get_response
    response = callback(request, *callback_args, **callback_kwargs)
  File "C:\Projects\dis_dk\invites_project\invites\views.py", line
242, in OptionEdit
    formset.save()
  File "C:\Program Files\Python25\Lib\site-packages\django\forms
\models.py", line 389, in save
    return self.save_existing_objects(commit) + self.save_new_objects
(commit)
  File "C:\Program Files\Python25\Lib\site-packages\django\forms
\models.py", line 403, in save_existing_objects
    obj = existing_objects[form.cleaned_data[self._pk_field.name]]
AttributeError: 'OptionForm' object has no attribute 'cleaned_data'

Code:
models.py:
---------
class Option(models.Model):
    option_name = models.CharField(max_length=200)
    option_value = models.CharField(max_length=200)
    default_selected = models.BooleanField(default=False)
    def __unicode__(self):
        return self.option_name


views.py:
--------
from models import Option

def OptionEdit(request, invite_id=None, form_id=None, field_id=None):
    from django.forms.models import modelformset_factory
    instance = Option.objects.all()
    if request.method == 'POST':
        OptionFormSet = modelformset_factory(Option)
        formset = OptionFormSet(request.POST, request.FILES,
queryset=instance)
        formset.save()
        return HttpResponseRedirect(reverse(OptionEdit, args=
[invite_id, form_id, field_id]))
    else:
        OptionFormSet = modelformset_factory(Option, extra=2,
can_delete=True)
        formset = OptionFormSet(queryset=instance)
        return render_to_response('invites/options_edit.html', {
                                'formset': formset,
                                'invite_id': invite_id,
                                'form_id': form_id,
                                 })

options_edit.html:
-----------------
<form name="frm1" method="post" action="">
        <table>
                {{ formset }}
                <tr>
                        <td colspan="2"><hr /></td>
                </tr>
        </table>
        <input type="submit" />
</form>


So, I'm really appreciate if you could help out an old VB coder with
this mess. Otherwive it seems like a super framework, if you only
could decode those error messages that's not very clear all the time.

Thanks!
/Martin

--~--~---------~--~----~------------~-------~--~----~
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+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to