Jani Rahkola
unread,Jun 13, 2010, 7:06:47 PM6/13/10Sign in to reply to author
Sign in to forward
You do not have permission to delete messages in this group
Sign in to report message
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to Django users
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.