wq/django-data-wizard

TypeError at /datawizard/

mureiken opened this issue · 2 comments

Hi,

I am trying to import an XML file.

I am getting this error

Request Method: | POST
Request URL: | http://127.0.0.1:8000/datawizard/
Django Version: | 2.0.6
Exception Type: | TypeError
Exception Value: | int() argument must be a string, a bytes-like object or a number, not 'ContentType'
Exception Location: | /Applications/Django/venv/lib/python3.6/site-packages/django/db/models/fields/init.py in get_prep_value, line 947
Python Executable: | /Applications/Django/venv/bin/python
Python Version: | 3.6.4
.....
.....
Error during template rendering
In template /Applications/Django/myvenv3/lib/python3.6/site-packages/rest_framework/templates/rest_framework/horizontal/select.html, error at line 15

` {% if field.allow_null or field.allow_blank %} -------- {% endif %} {% for select in field.iter_options %} # This is line 15 {% if select.start_option_group %} {% elif select.end_option_group %}`

Hey @mureiken ,
I had the same error using Django 1.11, Python 3.6, restframework 3.8.2, running on Ubuntu 18.04
This is how I solved it, it is an ugly / dirty fix, I know, but at least I was able to have my code running.
In data_wizard package open serializers.py and to go line 27, find following lines

def to_representation(self, content_type_id):
        ct = ContentType.objects.get(pk=content_type_id)
        return '%s.%s' % (ct.app_label, ct.model)

and replace those with code below

def to_representation(self, content_type_id):
        if type(content_type_id) is int:
            ct = ContentType.objects.get(pk=content_type_id)
        else:
            ct = ContentType.objects.get(pk=content_type_id.pk)
        return '%s.%s' % (ct.app_label, ct.model)

I kept the name of input argument the same name in case function is being called elsewhere using the argument names. I know it is a dirty fix, but at least my application is working, hope it helps you

I fixed the implementation of the ContentTypeIdField so the workaround should no longer be needed. Thanks for reporting!