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
This commit is contained in:
Brian Rosner 2008-11-15 02:20:00 +00:00
parent 0349d83289
commit f63929dbe2
2 changed files with 16 additions and 1 deletions

View File

@ -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 '&nbsp;<strong>%s</strong>' % truncate_words(obj, 14)
class ManyToManyRawIdWidget(ForeignKeyRawIdWidget):

View File

@ -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={})
<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(''),