I’m getting the error below when trying to load my Category. The value posted is ‘1’ and exists in the DB,
TypeError at /events/add/
int() argument must be a string or a number, not 'Category'
Request Method: POST
Request URL: http://127.0.0.1:8000/events/new/
Django Version: 1.4
Exception Type: TypeError
Exception Value:
int() argument must be a string or a number, not 'Category'
Exception Location: /Library/Python/2.7/site-packages/django/db/models/fields/__init__.py in get_prep_value, line 537
Python Executable: /Users/user/Documents/workspace/RoseBud/django-env/bin/python
views.py
category = Category.objects.get(pk=form.cleaned_data['category'])
sounds like the object returned by
form.cleaned_data['category']is a category object, not a number.If that’s the case, just do
category = form.cleaned_data['category']print it to be sure.