Hei, I hope someone could shed some light on this one. I have these in their appropriate files:
class ShoppinglistForm(ModelForm): def __init__(self, user=False, *args, **kwargs): ModelForm.__init__(self, *args, **kwargs) self.fields['pantry'].empty_label = None if user: self.fields['pantry'].queryset = Product.objects.filter(owner=user) class Meta: model = Shoppinglist def new(request): if request.method == 'POST': form = ShoppinglistForm(request.POST) if form.is_valid(): try: list = Shoppinglist(name=form.cleaned_data['name'], pantry=form.cleaned_data['pantry']) list.save() return redirect('blackem.users.views.home') except ObjectDoesNotExist: return redirect('blackem.users.views.home') else: form = ShoppinglistForm(user = request.user) return render_to_response('shoppinglists/shoppinglist_form.html', {'form': form, 'logged': True}, context_instance=RequestContext(request)) After pressing Submit on the form, I get this: Traceback: File "/usr/lib/python2.6/site-packages/django/core/handlers/base.py" in get_response 100. response = callback(request, *callback_args, **callback_kwargs) File "/usr/lib/python2.6/site-packages/django/contrib/auth/ decorators.py" in _wrapped_view 25. return view_func(request, *args, **kwargs) File "/home/jani/projects/blackem/shoppinglists/views.py" in new 20. form = ShoppinglistForm(request.POST) File "/home/jani/projects/blackem/shoppinglists/models.py" in __init__ 18. self.fields['pantry'].queryset = Pantry.objects.filter(owner=my_user) File "/usr/lib/python2.6/site-packages/django/db/models/manager.py" in filter 141. return self.get_query_set().filter(*args, **kwargs) File "/usr/lib/python2.6/site-packages/django/db/models/query.py" in filter 550. return self._filter_or_exclude(False, *args, **kwargs) File "/usr/lib/python2.6/site-packages/django/db/models/query.py" in _filter_or_exclude 568. clone.query.add_q(Q(*args, **kwargs)) File "/usr/lib/python2.6/site-packages/django/db/models/sql/query.py" in add_q 1131. can_reuse=used_aliases) File "/usr/lib/python2.6/site-packages/django/db/models/sql/query.py" in add_filter 1071. connector) File "/usr/lib/python2.6/site-packages/django/db/models/sql/where.py" in add 66. value = obj.prepare(lookup_type, value) File "/usr/lib/python2.6/site-packages/django/db/models/sql/where.py" in prepare 299. return self.field.get_prep_lookup(lookup_type, value) File "/usr/lib/python2.6/site-packages/django/db/models/fields/ related.py" in get_prep_lookup 134. return self._pk_trace(value, 'get_prep_lookup', lookup_type) File "/usr/lib/python2.6/site-packages/django/db/models/fields/ related.py" in _pk_trace 196. v = getattr(field, prep_func)(lookup_type, v, **kwargs) File "/usr/lib/python2.6/site-packages/django/db/models/fields/ __init__.py" in get_prep_lookup 292. return self.get_prep_value(value) File "/usr/lib/python2.6/site-packages/django/db/models/fields/ __init__.py" in get_prep_value 476. return int(value) Exception Type: TypeError at /shoppinglists/new Exception Value: int() argument must be a string or a number, not 'QueryDict' Taking away the 'user' keyword argument makes it work nicely. But I need to include only the user's pantries in the choices of the select wiget. -- 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.