Ticket #20207: 0001-Fixed-20207-Handle-ManyToManyField-with-a-unicode-na.patch

File 0001-Fixed-20207-Handle-ManyToManyField-with-a-unicode-na.patch, 2.1 KB (added by Simon Charette, 12 years ago)
  • django/db/models/fields/related.py

    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):  
    13091309        to = field.rel.to._meta.object_name
    13101310        to_model = field.rel.to
    13111311        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))
    13131313    if field.rel.to == RECURSIVE_RELATIONSHIP_CONSTANT or to == klass._meta.object_name:
    13141314        from_ = 'from_%s' % to.lower()
    13151315        to = 'to_%s' % to.lower()
  • tests/many_to_many/models.py

    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()``.  
    66In this example, an ``Article`` can be published in multiple ``Publication``
    77objects, and a ``Publication`` has multiple ``Article`` objects.
    88"""
     9from __future__ import unicode_literals
    910
    1011from django.db import models
    1112from django.utils.encoding import python_2_unicode_compatible
    class Publication(models.Model):  
    2425@python_2_unicode_compatible
    2526class Article(models.Model):
    2627    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')
    2831
    2932    def __str__(self):
    3033        return self.headline
Back to Top