Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

[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
Brian Rosner authored
2  django/contrib/admin/widgets.py
@@ -146,7 +146,7 @@ def url_parameters(self):
146 146
             
147 147
     def label_for_value(self, value):
148 148
         key = self.rel.get_related_field().name
149  
-        obj = self.rel.to.objects.get(**{key: value})
  149
+        obj = self.rel.to._default_manager.get(**{key: value})
150 150
         return '&nbsp;<strong>%s</strong>' % truncate_words(obj, 14)
151 151
 
152 152
 class ManyToManyRawIdWidget(ForeignKeyRawIdWidget):
15  tests/regressiontests/admin_widgets/models.py
@@ -24,10 +24,19 @@ class Album(models.Model):
24 24
     def __unicode__(self):
25 25
         return self.name
26 26
 
  27
+class HiddenInventoryManager(models.Manager):
  28
+    def get_query_set(self):
  29
+        return super(HiddenInventoryManager, self).get_query_set().filter(hidden=False) 
  30
+
27 31
 class Inventory(models.Model):
28 32
    barcode = models.PositiveIntegerField(unique=True)
29 33
    parent = models.ForeignKey('self', to_field='barcode', blank=True, null=True)
30 34
    name = models.CharField(blank=False, max_length=20)
  35
+   hidden = models.BooleanField(default=False)
  36
+   
  37
+   # see #9258
  38
+   default_manager = models.Manager()
  39
+   objects = HiddenInventoryManager()
31 40
 
32 41
    def __unicode__(self):
33 42
       return self.name
@@ -101,6 +110,12 @@ def __unicode__(self):
101 110
 >>> w = ForeignKeyRawIdWidget(rel)
102 111
 >>> print w.render('test', core.parent_id, attrs={})
103 112
 <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>
  113
+
  114
+# see #9258
  115
+>>> hidden = Inventory.objects.create(barcode=93, name='Hidden', hidden=True) 
  116
+>>> child_of_hidden = Inventory.objects.create(barcode=94, name='Child of hidden', parent=hidden)
  117
+>>> print w.render('test', child_of_hidden.parent_id, attrs={}) 
  118
+<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>
104 119
 """ % {
105 120
     'ADMIN_MEDIA_PREFIX': settings.ADMIN_MEDIA_PREFIX,
106 121
     'STORAGE_URL': default_storage.url(''),

0 notes on commit 781a176

Please sign in to comment.
Something went wrong with that request. Please try again.