mirror of
https://github.com/django/django.git
synced 2024-11-29 22:56:46 +01:00
Fix wrong attribute name in [15156]. Thanks to Alex Gaynor for spotting this.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@15169 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
parent
937548bba4
commit
ea774bf9a7
@ -371,8 +371,8 @@ class QuerySet(object):
|
|||||||
defaults = kwargs.pop('defaults', {})
|
defaults = kwargs.pop('defaults', {})
|
||||||
lookup = kwargs.copy()
|
lookup = kwargs.copy()
|
||||||
for f in self.model._meta.fields:
|
for f in self.model._meta.fields:
|
||||||
if f.column in lookup:
|
if f.attname in lookup:
|
||||||
lookup[f.name] = lookup.pop(f.column)
|
lookup[f.name] = lookup.pop(f.attname)
|
||||||
try:
|
try:
|
||||||
self._for_write = True
|
self._for_write = True
|
||||||
return self.get(**lookup), False
|
return self.get(**lookup), False
|
||||||
|
@ -10,4 +10,4 @@ class Author(models.Model):
|
|||||||
class Book(models.Model):
|
class Book(models.Model):
|
||||||
name = models.CharField(max_length=100)
|
name = models.CharField(max_length=100)
|
||||||
authors = models.ManyToManyField(Author, related_name='books')
|
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")
|
||||||
|
@ -55,8 +55,10 @@ class GetOrCreateTests(TestCase):
|
|||||||
# Use the publisher's primary key value instead of a model instance.
|
# 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)
|
_, created = ed.books.get_or_create(name='The Great Book of Ed', publisher_id=p.id)
|
||||||
self.assertTrue(created)
|
self.assertTrue(created)
|
||||||
|
|
||||||
# Try get_or_create again, this time nothing should be 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)
|
_, created = ed.books.get_or_create(name='The Great Book of Ed', publisher_id=p.id)
|
||||||
self.assertFalse(created)
|
self.assertFalse(created)
|
||||||
|
|
||||||
# The publisher should have three books.
|
# The publisher should have three books.
|
||||||
self.assertEqual(p.books.count(), 3)
|
self.assertEqual(p.books.count(), 3)
|
||||||
|
Loading…
Reference in New Issue
Block a user