TypeError while using django Form in editing an Entry

Posted by damon on Stack Overflow See other posts from Stack Overflow or by damon
Published on 2012-11-13T04:57:34Z Indexed on 2012/11/13 4:59 UTC
Read the original article Hit count: 150

Filed under:
|

I have an Entry model which can belong to a Category.I am providing a CategoryChoicesForm sothat the user can choose from various Categorys (from a dropdown list)when an Entry is created or edited.

I am having trouble with the CategoryChoicesForm while editing the Entry.It throws a TypeError..

If somebody can make out what is happening..please advise me how to correct this.

int() argument must be a string or a number, not 'QueryDict'
  /home/Django-1.4/django/db/models/fields/__init__.py in get_prep_value, line 537

    ...views.py in edit_entry
        category_choices_form = CategoryChoicesForm(form_data)
    ...
    ...forms.py in __init__

    self.fields['categoryoption'].queryset =   Category.objects.filter(creator=self.creator)

Here is the form

class CategoryChoicesForm(forms.Form):
    categoryoption = forms.ModelChoiceField(
                           queryset = Category.objects.none(),
                           required=False,label='Category')
    def __init__(self, categorycreator,*args, **kwargs):
        super(CategoryChoicesForm, self).__init__(*args, **kwargs)
        self.creator=categorycreator
        self.fields['categoryoption'].queryset = Category.objects.filter(creator=self.creator)

The edit_entry view is as follows

@login_required
@transaction.commit_on_success
def edit_entry(request,id,template_name,page_title):
    form_data = get_form_data(request)
    entry = get_object_or_404(Entry,pk=id,author=request.user)
    ...
    category_choices_form = CategoryChoicesForm(form_data)
    ...

© Stack Overflow or respective owner

Related posts about django

Related posts about forms