Code

Ticket #4492: ticket-4492_r5743.diff

File ticket-4492_r5743.diff, 3.4 KB (added by John Shaffer <jshaffer2112@…>, 7 years ago)

Patch against [5743], with tests.

Line 
1Index: django/db/backends/postgresql/base.py
2===================================================================
3--- django/db/backends/postgresql/base.py       (revision 5743)
4+++ django/db/backends/postgresql/base.py       (working copy)
5@@ -271,7 +271,7 @@
6                 style.SQL_FIELD(quote_name('id')),
7                 style.SQL_KEYWORD('IS NOT'),
8                 style.SQL_KEYWORD('FROM'),
9-                style.SQL_TABLE(f.m2m_db_table())))
10+                style.SQL_TABLE(quote_name(f.m2m_db_table()))))
11     return output
12 
13 def typecast_string(s):
14Index: django/db/backends/postgresql_psycopg2/base.py
15===================================================================
16--- django/db/backends/postgresql_psycopg2/base.py      (revision 5743)
17+++ django/db/backends/postgresql_psycopg2/base.py      (working copy)
18@@ -221,7 +221,7 @@
19                 style.SQL_FIELD(quote_name('id')),
20                 style.SQL_KEYWORD('IS NOT'),
21                 style.SQL_KEYWORD('FROM'),
22-                style.SQL_TABLE(f.m2m_db_table())))
23+                style.SQL_TABLE(quote_name(f.m2m_db_table()))))
24     return output
25 
26 OPERATOR_MAPPING = {
27Index: tests/modeltests/fixtures/fixtures/fixture6.json
28===================================================================
29--- tests/modeltests/fixtures/fixtures/fixture6.json    (revision 0)
30+++ tests/modeltests/fixtures/fixtures/fixture6.json    (revision 0)
31@@ -0,0 +1,18 @@
32+[
33+    {
34+        "pk": "7",
35+        "model": "fixtures.mixedcasem2m",
36+        "fields": {
37+            "relatedItems": [],
38+            "Title": "Poker has no place on ESPN"
39+        }
40+    },
41+    {
42+        "pk": "9",
43+        "model": "fixtures.mixedcasem2m",
44+        "fields": {
45+            "relatedItems": [7],
46+            "Title": "Time to reform copyright"
47+        }
48+    }
49+]
50Index: tests/modeltests/fixtures/models.py
51===================================================================
52--- tests/modeltests/fixtures/models.py (revision 5743)
53+++ tests/modeltests/fixtures/models.py (working copy)
54@@ -20,6 +20,16 @@
55     class Meta:
56         ordering = ('-pub_date', 'headline')
57 
58+class MixedCaseM2M(models.Model):
59+    relatedItems = models.ManyToManyField('self', blank=True, null=True)
60+    Title = models.CharField(maxlength=100, default='Default title')
61+
62+    def __unicode__(self):
63+        return self.Title
64+
65+    class Meta:
66+        ordering = ('Title',)
67+
68 __test__ = {'API_TESTS': """
69 >>> from django.core import management
70 >>> from django.db.models import get_app
71@@ -75,6 +85,14 @@
72 # Dump the current contents of the database as a JSON fixture
73 >>> print management.dump_data(['fixtures'], format='json')
74 [{"pk": "3", "model": "fixtures.article", "fields": {"headline": "Time to reform copyright", "pub_date": "2006-06-16 13:00:00"}}, {"pk": "2", "model": "fixtures.article", "fields": {"headline": "Poker has no place on ESPN", "pub_date": "2006-06-16 12:00:00"}}, {"pk": "1", "model": "fixtures.article", "fields": {"headline": "Python program becomes self aware", "pub_date": "2006-06-16 11:00:00"}}]
75+
76+# Load fixture 6: a JSON file with mixed-case column names.
77+>>> management.load_data(['fixture6.json'], verbosity=0)
78+>>> MixedCaseM2M.objects.all()
79+[<MixedCaseM2M: Poker has no place on ESPN>, <MixedCaseM2M: Time to reform copyright>]
80+>>> mixed = MixedCaseM2M.objects.get(Title__icontains='poker')
81+>>> mixed.relatedItems.all()
82+[<MixedCaseM2M: Time to reform copyright>]
83 """}
84 
85 from django.test import TestCase