From 9a31b33a5a95a07e40349d562805b2beb154a342 Mon Sep 17 00:00:00 2001
From: Simon Charette <charette.s@gmail.com>
Date: Fri, 5 Apr 2013 13:59:15 -0400
Subject: [PATCH] Fixed #20207 -- Handle ManyToManyField with a unicode name
correctly.
---
django/db/models/fields/related.py | 2 +-
tests/many_to_many/models.py | 5 ++++-
2 files changed, 5 insertions(+), 2 deletions(-)
diff --git a/django/db/models/fields/related.py b/django/db/models/fields/related.py
index 677a470..4785d58 100644
a
|
b
|
def create_many_to_many_intermediary_model(field, klass):
|
1309 | 1309 | to = field.rel.to._meta.object_name |
1310 | 1310 | to_model = field.rel.to |
1311 | 1311 | managed = klass._meta.managed or to_model._meta.managed |
1312 | | name = '%s_%s' % (klass._meta.object_name, field.name) |
| 1312 | name = str('%s_%s' % (klass._meta.object_name, field.name)) |
1313 | 1313 | if field.rel.to == RECURSIVE_RELATIONSHIP_CONSTANT or to == klass._meta.object_name: |
1314 | 1314 | from_ = 'from_%s' % to.lower() |
1315 | 1315 | to = 'to_%s' % to.lower() |
diff --git a/tests/many_to_many/models.py b/tests/many_to_many/models.py
index a196c85..809820e 100644
a
|
b
|
To define a many-to-many relationship, use ``ManyToManyField()``.
|
6 | 6 | In this example, an ``Article`` can be published in multiple ``Publication`` |
7 | 7 | objects, and a ``Publication`` has multiple ``Article`` objects. |
8 | 8 | """ |
| 9 | from __future__ import unicode_literals |
9 | 10 | |
10 | 11 | from django.db import models |
11 | 12 | from django.utils.encoding import python_2_unicode_compatible |
… |
… |
class Publication(models.Model):
|
24 | 25 | @python_2_unicode_compatible |
25 | 26 | class Article(models.Model): |
26 | 27 | headline = models.CharField(max_length=100) |
27 | | publications = models.ManyToManyField(Publication) |
| 28 | # Assign a unicode string asname to make sure the intermediary model is |
| 29 | # correctly created. Refs #20207 |
| 30 | publications = models.ManyToManyField(Publication, name='publications') |
28 | 31 | |
29 | 32 | def __str__(self): |
30 | 33 | return self.headline |