﻿id	summary	reporter	owner	description	type	status	component	version	severity	resolution	keywords	cc	stage	has_patch	needs_docs	needs_tests	needs_better_patch	easy	ui_ux
16299	Django model-module doesn't support unicode_literals	martijn.bastiaan@…	nobody	"Hello all,

When using 
{{{
from __future__ import unicode_literals
}}}
in a model file, Django fails to recognize a model referenced by a string and raises a quite obscure error message:
{{{
Traceback (most recent call last):
  File ""test.py"", line 5, in <module>
    a = article.Article.objects.get(id=57220255)
  File ""/usr/local/lib/django/django/db/models/manager.py"", line 132, in get
    return self.get_query_set().get(*args, **kwargs)
  File ""/usr/local/lib/django/django/db/models/query.py"", line 341, in get
    clone = self.filter(*args, **kwargs)
  File ""/usr/local/lib/django/django/db/models/query.py"", line 550, in filter
    return self._filter_or_exclude(False, *args, **kwargs)
  File ""/usr/local/lib/django/django/db/models/query.py"", line 568, in _filter_or_exclude
    clone.query.add_q(Q(*args, **kwargs))
  File ""/usr/local/lib/django/django/db/models/sql/query.py"", line 1172, in add_q
    can_reuse=used_aliases, force_having=force_having)
  File ""/usr/local/lib/django/django/db/models/sql/query.py"", line 1060, in add_filter
    negate=negate, process_extras=process_extras)
  File ""/usr/local/lib/django/django/db/models/sql/query.py"", line 1226, in setup_joins
    field, model, direct, m2m = opts.get_field_by_name(name)
  File ""/usr/local/lib/django/django/db/models/options.py"", line 307, in get_field_by_name
    cache = self.init_name_map()
  File ""/usr/local/lib/django/django/db/models/options.py"", line 339, in init_name_map
    for f, model in self.get_all_related_objects_with_model():
  File ""/usr/local/lib/django/django/db/models/options.py"", line 371, in get_all_related_objects_with_model
    self._fill_related_objects_cache()
  File ""/usr/local/lib/django/django/db/models/options.py"", line 393, in _fill_related_objects_cache
    if f.rel and not isinstance(f.rel.to, str) and self == f.rel.to._meta:
AttributeError: 'unicode' object has no attribute '_meta'
}}}

Model example:
{{{
    insert_user = models.ForeignKey(""models.User"", db_column='insertuser_id')

    # Or without from __future__ import unicode_literals
    insert_user = models.ForeignKey(u""models.User"", db_column='insertuser_id')
}}}

I've attached a patch.

Yours,
Martijn
"	Bug	closed	Database layer (models, ORM)	dev	Normal	fixed	unicode, ForeignKey, AttributeError		Accepted	1	0	0	0	1	0
