Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

[1.2.X] Fix wrong attribute name in [15156]. Thanks to Alex Gaynor fo…

…r spotting this.

Backport of [15169] from trunk

git-svn-id: http://code.djangoproject.com/svn/django/branches/releases/1.2.X@15170 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit 663eb9656a92492bb43a5a29efed9d907dc8f6ae 1 parent 03ab30c
@andrewgodwin andrewgodwin authored
View
4 django/db/models/query.py
@@ -369,8 +369,8 @@ def get_or_create(self, **kwargs):
defaults = kwargs.pop('defaults', {})
lookup = kwargs.copy()
for f in self.model._meta.fields:
- if f.column in lookup:
- lookup[f.name] = lookup.pop(f.column)
+ if f.attname in lookup:
+ lookup[f.name] = lookup.pop(f.attname)
try:
self._for_write = True
return self.get(**lookup), False
View
2  tests/regressiontests/get_or_create_regress/models.py
@@ -10,4 +10,4 @@ class Author(models.Model):
class Book(models.Model):
name = models.CharField(max_length=100)
authors = models.ManyToManyField(Author, related_name='books')
- publisher = models.ForeignKey(Publisher, related_name='books')
+ publisher = models.ForeignKey(Publisher, related_name='books', db_column="publisher_id_column")
View
2  tests/regressiontests/get_or_create_regress/tests.py
@@ -55,8 +55,10 @@ def test_related(self):
# Use the publisher's primary key value instead of a model instance.
_, created = ed.books.get_or_create(name='The Great Book of Ed', publisher_id=p.id)
self.assertTrue(created)
+
# Try get_or_create again, this time nothing should be created.
_, created = ed.books.get_or_create(name='The Great Book of Ed', publisher_id=p.id)
self.assertFalse(created)
+
# The publisher should have three books.
self.assertEqual(p.books.count(), 3)
Please sign in to comment.
Something went wrong with that request. Please try again.