Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

[1.0.X] Fixed #9258 -- Use _default_manager in ForeignKeyRawIdWidget.…

…label_for_value. Thanks nullie for the patch.

Backport of r9444 from trunk.

git-svn-id: http://code.djangoproject.com/svn/django/branches/releases/1.0.X@9445 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit 781a1763d94c7e867d9ba80b3f075526510a3482 1 parent 014c563
@brosner brosner authored
View
2  django/contrib/admin/widgets.py
@@ -146,7 +146,7 @@ def url_parameters(self):
def label_for_value(self, value):
key = self.rel.get_related_field().name
- obj = self.rel.to.objects.get(**{key: value})
+ obj = self.rel.to._default_manager.get(**{key: value})
return '&nbsp;<strong>%s</strong>' % truncate_words(obj, 14)
class ManyToManyRawIdWidget(ForeignKeyRawIdWidget):
View
15 tests/regressiontests/admin_widgets/models.py
@@ -24,10 +24,19 @@ class Album(models.Model):
def __unicode__(self):
return self.name
+class HiddenInventoryManager(models.Manager):
+ def get_query_set(self):
+ return super(HiddenInventoryManager, self).get_query_set().filter(hidden=False)
+
class Inventory(models.Model):
barcode = models.PositiveIntegerField(unique=True)
parent = models.ForeignKey('self', to_field='barcode', blank=True, null=True)
name = models.CharField(blank=False, max_length=20)
+ hidden = models.BooleanField(default=False)
+
+ # see #9258
+ default_manager = models.Manager()
+ objects = HiddenInventoryManager()
def __unicode__(self):
return self.name
@@ -101,6 +110,12 @@ def __unicode__(self):
>>> w = ForeignKeyRawIdWidget(rel)
>>> print w.render('test', core.parent_id, attrs={})
<input type="text" name="test" value="86" class="vForeignKeyRawIdAdminField" /><a href="../../../admin_widgets/inventory/?t=barcode" class="related-lookup" id="lookup_id_test" onclick="return showRelatedObjectLookupPopup(this);"> <img src="%(ADMIN_MEDIA_PREFIX)simg/admin/selector-search.gif" width="16" height="16" alt="Lookup" /></a>&nbsp;<strong>Apple</strong>
+
+# see #9258
+>>> hidden = Inventory.objects.create(barcode=93, name='Hidden', hidden=True)
+>>> child_of_hidden = Inventory.objects.create(barcode=94, name='Child of hidden', parent=hidden)
+>>> print w.render('test', child_of_hidden.parent_id, attrs={})
+<input type="text" name="test" value="93" class="vForeignKeyRawIdAdminField" /><a href="../../../admin_widgets/inventory/?t=barcode" class="related-lookup" id="lookup_id_test" onclick="return showRelatedObjectLookupPopup(this);"> <img src="%(ADMIN_MEDIA_PREFIX)simg/admin/selector-search.gif" width="16" height="16" alt="Lookup" /></a>&nbsp;<strong>Hidden</strong>
""" % {
'ADMIN_MEDIA_PREFIX': settings.ADMIN_MEDIA_PREFIX,
'STORAGE_URL': default_storage.url(''),
Please sign in to comment.
Something went wrong with that request. Please try again.