From 5d428908218e3692d1bc7e4ada6235029ae9e45c Mon Sep 17 00:00:00 2001
From: Markus Holtermann <info@markusholtermann.eu>
Date: Wed, 10 Jun 2015 20:19:21 +0200
Subject: [PATCH] Fixed #24950 -- Added unicode_literals to models.py in app
 template

Thanks Tim Graham for the patch
---
 django/conf/app_template/models.py  | 2 +-
 django/core/management/templates.py | 3 ++-
 tests/admin_scripts/tests.py        | 9 ++++++++-
 3 files changed, 11 insertions(+), 3 deletions(-)

diff --git a/django/conf/app_template/models.py b/django/conf/app_template/models.py
index 71a8362390..7a54b3e371 100644
--- a/django/conf/app_template/models.py
+++ b/django/conf/app_template/models.py
@@ -1,3 +1,3 @@
-from django.db import models
+{{ unicode_literals }}from django.db import models
 
 # Create your models here.
diff --git a/django/core/management/templates.py b/django/core/management/templates.py
index eb5340dc88..2aa9b021a2 100644
--- a/django/core/management/templates.py
+++ b/django/core/management/templates.py
@@ -14,7 +14,7 @@ import django
 from django.core.management.base import BaseCommand, CommandError
 from django.core.management.utils import handle_extensions
 from django.template import Context, Engine
-from django.utils import archive
+from django.utils import archive, six
 from django.utils.six.moves.urllib.request import urlretrieve
 from django.utils.version import get_docs_version
 
@@ -104,6 +104,7 @@ class TemplateCommand(BaseCommand):
             base_directory: top_dir,
             'docs_version': get_docs_version(),
             'django_version': django.__version__,
+            'unicode_literals': '' if six.PY3 else 'from __future__ import unicode_literals\n\n',
         }), autoescape=False)
 
         # Setup a stub settings environment for template rendering
diff --git a/tests/admin_scripts/tests.py b/tests/admin_scripts/tests.py
index 7c07a51796..4b17690c1d 100644
--- a/tests/admin_scripts/tests.py
+++ b/tests/admin_scripts/tests.py
@@ -31,7 +31,7 @@ from django.test import (
 from django.test.runner import DiscoverRunner
 from django.utils._os import npath, upath
 from django.utils.encoding import force_text
-from django.utils.six import StringIO
+from django.utils.six import PY3, StringIO
 
 test_dir = os.path.realpath(os.path.join(tempfile.gettempdir(), 'test_project'))
 if not os.path.exists(test_dir):
@@ -592,6 +592,13 @@ class DjangoAdminSettingsDirectory(AdminScriptTestCase):
         self.addCleanup(shutil.rmtree, app_path)
         self.assertNoOutput(err)
         self.assertTrue(os.path.exists(app_path))
+        if not PY3:
+            with open(os.path.join(app_path, 'models.py'), 'r') as fp:
+                content = fp.read()
+            self.assertIn(
+                "from __future__ import unicode_literals\n",
+                content,
+            )
 
     def test_setup_environ_custom_template(self):
         "directory: startapp creates the correct directory with a custom template"