All instances of model creation due to "coercing to Unicode" error

Viewed 87

I have a Django project with two functional apps in it. Today, after adding two new models I realised one of my apps is broken. When I try to add an instance to any of the models I get an error related to the data type. This happens when I try to create an instance of any model within the app. Also this even happens when I try to create an instance through the Django admin interface! In the admin interface I am even not able to delete an instance without getting the same error.

I have copied below my main model, as well as the traceback on creating an instance and viewing the model in the admin interface.

from django.db import models
from django.template.defaultfilters import slugify
from django.utils.translation import ugettext_lazy as _
from django.contrib.auth.models import User
import datetime

class DrukOrder(models.Model):
    inkoop = models.CharField(max_length=16, default=0, unique=True)
    order = models.IntegerField(default=0)
    beschrijving = models.CharField(max_length=1024)
    crediteur = models.IntegerField(default=0)
    leverancier = models.CharField(max_length=1024, null=True)
    medewerker = models.CharField(max_length=128, null=True)

    besteldatum = models.DateField(null=True)
    ontvangstdatum = models.DateField(null=True)
    factuurdatum = models.DateField(null=True)
    leverancierdatum = models.DateField(null=True)
    oorspronkelijkedatum = models.DateField(null=True)

    klant = models.CharField(max_length=1024, null=True)
    kleuren = models.IntegerField(null=True)
    rolbreedte = models.DecimalField(max_digits=5, decimal_places=2, default=0)
    leveringweek = models.IntegerField(null=True)
    materiaal = models.CharField(max_length=1024, null=True)
    offerte = models.CharField(max_length=1024, null=True)
    vrijetekst = models.CharField(max_length=2048, null=True)

    datum = models.DateTimeField(auto_now=True, null=True)
    user = models.ForeignKey(User, null=True)
    aanmaakdatum = models.DateTimeField(null=True)
    wijzigingdatum = models.DateTimeField(null=True)
    status = models.CharField(max_length=128, null=True)
    actief = models.BooleanField(default=True)
    slug = models.SlugField(null=True)

    class Meta:
        unique_together = ('order', 'crediteur',)

    def save(self, *args, **kwargs):
        self.slug = slugify(self.inkoop)
        super(DrukOrder, self).save(*args, **kwargs)

    def __unicode__(self):
        return self.id

Traceback for loading the model in the admin interface:

Environment:


Request Method: GET
Request URL: http://pim.local:8000/admin/pam/drukorder/

Django Version: 1.8
Python Version: 2.7.6
Installed Applications:
('django.contrib.admin',
 'django.contrib.auth',
 'django.contrib.contenttypes',
 'django.contrib.sessions',
 'django.contrib.messages',
 'django.contrib.staticfiles',
 'django.contrib.humanize',
 'registration',
 'bootstrap3_datetime',
 'pim',
 'pam')
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')


Template error:
In template /home/administrator/.virtualenvs/pim/local/lib/python2.7/site-packages/django/contrib/admin/templates/admin/change_list.html, error at line 91
   coercing to Unicode: need string or buffer, int found

   81 :         {% endif %}



   82 :       {% endblock %}



   83 : 



   84 :       <form id="changelist-form" action="" method="post"{% if cl.formset.is_multipart %} enctype="multipart/form-data"{% endif %} novalidate>{% csrf_token %}



   85 :       {% if cl.formset %}



   86 :         <div>{{ cl.formset.management_form }}</div>



   87 :       {% endif %}



   88 : 



   89 :       {% block result_list %}



   90 :           {% if action_form and actions_on_top and cl.show_admin_actions %}{% admin_actions %}{% endif %}



   91 :            {% result_list cl %} 



   92 :           {% if action_form and actions_on_bottom and cl.show_admin_actions %}{% admin_actions %}{% endif %}



   93 :       {% endblock %}



   94 :       {% block pagination %}{% pagination cl %}{% endblock %}



   95 :       </form>



   96 :     </div>



   97 :   </div>



   98 : {% endblock %}



   99 : 

Traceback:
File "/home/administrator/.virtualenvs/pim/local/lib/python2.7/site-packages/django/core/handlers/base.py" in get_response
  164.                 response = response.render()
File "/home/administrator/.virtualenvs/pim/local/lib/python2.7/site-packages/django/template/response.py" in render
  158.             self.content = self.rendered_content
File "/home/administrator/.virtualenvs/pim/local/lib/python2.7/site-packages/django/template/response.py" in rendered_content
  135.         content = template.render(context, self._request)
File "/home/administrator/.virtualenvs/pim/local/lib/python2.7/site-packages/django/template/backends/django.py" in render
  74.         return self.template.render(context)
File "/home/administrator/.virtualenvs/pim/local/lib/python2.7/site-packages/django/template/base.py" in render
  209.                     return self._render(context)
File "/home/administrator/.virtualenvs/pim/local/lib/python2.7/site-packages/django/template/base.py" in _render
  201.         return self.nodelist.render(context)
File "/home/administrator/.virtualenvs/pim/local/lib/python2.7/site-packages/django/template/base.py" in render
  903.                 bit = self.render_node(node, context)
File "/home/administrator/.virtualenvs/pim/local/lib/python2.7/site-packages/django/template/debug.py" in render_node
  79.             return node.render(context)
File "/home/administrator/.virtualenvs/pim/local/lib/python2.7/site-packages/django/template/loader_tags.py" in render
  135.         return compiled_parent._render(context)
File "/home/administrator/.virtualenvs/pim/local/lib/python2.7/site-packages/django/template/base.py" in _render
  201.         return self.nodelist.render(context)
File "/home/administrator/.virtualenvs/pim/local/lib/python2.7/site-packages/django/template/base.py" in render
  903.                 bit = self.render_node(node, context)
File "/home/administrator/.virtualenvs/pim/local/lib/python2.7/site-packages/django/template/debug.py" in render_node
  79.             return node.render(context)
File "/home/administrator/.virtualenvs/pim/local/lib/python2.7/site-packages/django/template/loader_tags.py" in render
  135.         return compiled_parent._render(context)
File "/home/administrator/.virtualenvs/pim/local/lib/python2.7/site-packages/django/template/base.py" in _render
  201.         return self.nodelist.render(context)
File "/home/administrator/.virtualenvs/pim/local/lib/python2.7/site-packages/django/template/base.py" in render
  903.                 bit = self.render_node(node, context)
File "/home/administrator/.virtualenvs/pim/local/lib/python2.7/site-packages/django/template/debug.py" in render_node
  79.             return node.render(context)
File "/home/administrator/.virtualenvs/pim/local/lib/python2.7/site-packages/django/template/loader_tags.py" in render
  65.                 result = block.nodelist.render(context)
File "/home/administrator/.virtualenvs/pim/local/lib/python2.7/site-packages/django/template/base.py" in render
  903.                 bit = self.render_node(node, context)
File "/home/administrator/.virtualenvs/pim/local/lib/python2.7/site-packages/django/template/debug.py" in render_node
  79.             return node.render(context)
File "/home/administrator/.virtualenvs/pim/local/lib/python2.7/site-packages/django/template/loader_tags.py" in render
  65.                 result = block.nodelist.render(context)
File "/home/administrator/.virtualenvs/pim/local/lib/python2.7/site-packages/django/template/base.py" in render
  903.                 bit = self.render_node(node, context)
File "/home/administrator/.virtualenvs/pim/local/lib/python2.7/site-packages/django/template/debug.py" in render_node
  79.             return node.render(context)
File "/home/administrator/.virtualenvs/pim/local/lib/python2.7/site-packages/django/template/base.py" in render
  1271.                     _dict = func(*resolved_args, **resolved_kwargs)
File "/home/administrator/.virtualenvs/pim/local/lib/python2.7/site-packages/django/contrib/admin/templatetags/admin_list.py" in result_list
  320.             'results': list(results(cl))}
File "/home/administrator/.virtualenvs/pim/local/lib/python2.7/site-packages/django/contrib/admin/templatetags/admin_list.py" in results
  296.             yield ResultList(None, items_for_result(cl, res, None))
File "/home/administrator/.virtualenvs/pim/local/lib/python2.7/site-packages/django/contrib/admin/templatetags/admin_list.py" in __init__
  287.         super(ResultList, self).__init__(*items)
File "/home/administrator/.virtualenvs/pim/local/lib/python2.7/site-packages/django/contrib/admin/templatetags/admin_list.py" in items_for_result
  199.             f, attr, value = lookup_field(field_name, result, cl.model_admin)
File "/home/administrator/.virtualenvs/pim/local/lib/python2.7/site-packages/django/contrib/admin/utils.py" in lookup_field
  282.                 value = attr()
File "/home/administrator/.virtualenvs/pim/local/lib/python2.7/site-packages/django/db/models/base.py" in __str__
  503.             return force_text(self).encode('utf-8')
File "/home/administrator/.virtualenvs/pim/local/lib/python2.7/site-packages/django/utils/encoding.py" in force_text
  92.                 s = six.text_type(s)

Exception Type: TypeError at /admin/pam/drukorder/
Exception Value: coercing to Unicode: need string or buffer, int found

And the error when creating an instance of the main model:

TypeError: coercing to Unicode: need string or buffer, int found

I am really surprised about this sudden change, and that it affects all the models in only one of the apps. I have removed the new models and have removed all previously instances in all models. Creating new instances still fails, loading the admin interface still fails. Where should I start to troubleshoot this issue?

1 Answers
Related