From f63929dbe2f27733806d7f69d223682c4a72b450 Mon Sep 17 00:00:00 2001 From: Brian Rosner Date: Sat, 15 Nov 2008 02:20:00 +0000 Subject: [PATCH] Fixed #9258 -- Use _default_manager in ForeignKeyRawIdWidget.label_for_value. Thanks nullie for the patch. git-svn-id: http://code.djangoproject.com/svn/django/trunk@9444 bcc190cf-cafb-0310-a4f2-bffc1f526a37 --- django/contrib/admin/widgets.py | 2 +- tests/regressiontests/admin_widgets/models.py | 15 +++++++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/django/contrib/admin/widgets.py b/django/contrib/admin/widgets.py index 6a2d982351..e2cd2113f8 100644 --- a/django/contrib/admin/widgets.py +++ b/django/contrib/admin/widgets.py @@ -146,7 +146,7 @@ class ForeignKeyRawIdWidget(forms.TextInput): 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 ' %s' % truncate_words(obj, 14) class ManyToManyRawIdWidget(ForeignKeyRawIdWidget): diff --git a/tests/regressiontests/admin_widgets/models.py b/tests/regressiontests/admin_widgets/models.py index 19e2696b93..ddfc6c2cb6 100644 --- a/tests/regressiontests/admin_widgets/models.py +++ b/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 @@ True >>> w = ForeignKeyRawIdWidget(rel) >>> print w.render('test', core.parent_id, attrs={}) Lookup Apple + +# 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={}) + Lookup Hidden """ % { 'ADMIN_MEDIA_PREFIX': settings.ADMIN_MEDIA_PREFIX, 'STORAGE_URL': default_storage.url(''),