Forms Django - Error binding parameter 0 - type probably not supported

advertisements

When i try sending my form then I getting error like "Error binding parameter 0 - probably unsupported type.".

I checked my model and set blank=True for all of fields for test but doesn't help. Can you give me some advice where is a problem? or fresh look :)

My traceback:

Environment:

Request Method: POST
Request URL: http://127.0.0.1:8000/panel/order/create/19/

Django Version: 1.8.8
Python Version: 3.5.1
Installed Applications:
('django.contrib.admin',
 'django.contrib.auth',
 'django.contrib.contenttypes',
 'django.contrib.sessions',
 'django.contrib.messages',
 'django.contrib.staticfiles',
 'core',
 'client',
 'registration',
 'avatar',
 'filer',
 'mptt',
 'easy_thumbnails',
 'reversion',
 'guardian')
Installed Middleware:
('django.contrib.sessions.middleware.SessionMiddleware',
 'django.middleware.common.CommonMiddleware',
 'django.middleware.csrf.CsrfViewMiddleware',
 'django.contrib.auth.middleware.AuthenticationMiddleware',
 'django.contrib.auth.middleware.SessionAuthenticationMiddleware',
 'django.contrib.messages.middleware.MessageMiddleware',
 'django.middleware.clickjacking.XFrameOptionsMiddleware',
 'django.middleware.security.SecurityMiddleware')

Traceback:
File "C:\Users\loc\dJangoEnvironment\lib\site-packages\django\core\handlers\base.py" in get_response
  132.                     response = wrapped_callback(request, *callback_args, **callback_kwargs)
File "C:\Users\loc\dJangoEnvironment\lib\site-packages\django\contrib\auth\decorators.py" in _wrapped_view
  22.                 return view_func(request, *args, **kwargs)
File "C:\Users\loc\PycharmProjects\CRM\core\views.py" in order_create
  347.         form_order = OrderCreateForm(request.POST)
File "C:\Users\loc\PycharmProjects\CRM\core\forms.py" in __init__
  34.             Platform.objects.filter(client_id=request_client_id).values_list('id', 'name'))
File "C:\Users\loc\dJangoEnvironment\lib\site-packages\django\db\models\query.py" in __iter__
  162.         self._fetch_all()
File "C:\Users\loc\dJangoEnvironment\lib\site-packages\django\db\models\query.py" in _fetch_all
  965.             self._result_cache = list(self.iterator())
File "C:\Users\loc\dJangoEnvironment\lib\site-packages\django\db\models\query.py" in iterator
  1220.             for row in compiler.results_iter():
File "C:\Users\loc\dJangoEnvironment\lib\site-packages\django\db\models\sql\compiler.py" in results_iter
  794.             results = self.execute_sql(MULTI)
File "C:\Users\loc\dJangoEnvironment\lib\site-packages\django\db\models\sql\compiler.py" in execute_sql
  840.             cursor.execute(sql, params)
File "C:\Users\loc\dJangoEnvironment\lib\site-packages\django\db\backends\utils.py" in execute
  79.             return super(CursorDebugWrapper, self).execute(sql, params)
File "C:\Users\loc\dJangoEnvironment\lib\site-packages\django\db\backends\utils.py" in execute
  64.                 return self.cursor.execute(sql, params)
File "C:\Users\loc\dJangoEnvironment\lib\site-packages\django\db\utils.py" in __exit__
  98.                 six.reraise(dj_exc_type, dj_exc_value, traceback)
File "C:\Users\loc\dJangoEnvironment\lib\site-packages\django\utils\six.py" in reraise
  685.             raise value.with_traceback(tb)
File "C:\Users\loc\dJangoEnvironment\lib\site-packages\django\db\backends\utils.py" in execute
  64.                 return self.cursor.execute(sql, params)
File "C:\Users\loc\dJangoEnvironment\lib\site-packages\django\db\backends\sqlite3\base.py" in execute
  318.         return Database.Cursor.execute(self, query, params)

Exception Type: InterfaceError at /panel/order/create/19/
Exception Value: Error binding parameter 0 - probably unsupported type.

Forms.py:

BLANK_CHOICE = (('', '---------'),)

class OrderCreateForm(forms.ModelForm):
    tag_from = forms.MultipleChoiceField(label='Tags')
    tag_to = forms.MultipleChoiceField()

    class Meta:
        model = Order
        fields = ('price', 'client', 'platform')

    def __init__(self, request_client_id, *args, **kwargs):
        super(OrderCreateForm, self).__init__(*args, **kwargs)
        self.fields['platform'].choices = BLANK_CHOICE + tuple(
            Platform.objects.filter(client_id=request_client_id).values_list('id', 'name'))
        self.fields['tag_from'].choices = OrderItemList.objects.all().values_list('id', 'name')

View.py:

 @user_passes_test(lambda u: u.is_staff, login_url='/account/login/')
def order_create(request, request_client_id):
    dict = {}

    if request.method == 'POST':
        form_order = OrderCreateForm(request.POST)
       if form_order.is_valid():
            obj = form_order.save(commit=False)
            (...)
            obj.save()
            return HttpResponse('..')

        dict['form_order'] = form_order
        return render(request, 'panel/order/form.html', dict)
    else:
        dict['form_order'] = OrderCreateForm(request_client_id)
        return render(request, 'panel/order/form.html', dict)


Your form takes request_client_id as the first argument. Therefore you must pass request_client_id every time the form is submitted, including when you do a post request.

if request.method == 'POST':
    form_order = OrderCreateForm(request_client_id, request.POST)