Ticket #9258: foreing-key-raw-id-admin.diff
File foreing-key-raw-id-admin.diff, 3.2 KB (added by , 16 years ago) |
---|
-
django/contrib/admin/widgets.py
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 ' <strong>%s</strong>' % truncate_words(obj, 14) 151 151 152 152 class ManyToManyRawIdWidget(ForeignKeyRawIdWidget): -
tests/regressiontests/admin_widgets/models.py
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 barcode = models.PositiveIntegerField(unique=True) 29 parent = models.ForeignKey('self', to_field='barcode', blank=True, null=True) 30 name = models.CharField(blank=False, max_length=20) 32 hidden = models.BooleanField(default=False) 33 barcode = models.PositiveIntegerField(unique=True) 34 parent = models.ForeignKey('self', to_field='barcode', blank=True, null=True) 35 name = models.CharField(blank=False, max_length=20) 31 36 32 def __unicode__(self):33 return self.name37 default_manager = models.Manager() 38 objects = HiddenInventoryManager() 34 39 40 def __unicode__(self): 41 return self.name 42 35 43 __test__ = {'WIDGETS_TESTS': """ 36 44 >>> from datetime import datetime 37 45 >>> from django.utils.html import escape, conditional_escape … … 97 105 >>> apple = Inventory.objects.create(barcode=86, name='Apple') 98 106 >>> pear = Inventory.objects.create(barcode=22, name='Pear') 99 107 >>> core = Inventory.objects.create(barcode=87, name='Core', parent=apple) 108 >>> hidden = Inventory.objects.create(barcode=93, name='Hidden', hidden=True) 109 >>> child_of_hidden = Inventory.objects.create(barcode=94, name='Child of hidden', parent=hidden) 100 110 >>> rel = Inventory._meta.get_field('parent').rel 101 111 >>> w = ForeignKeyRawIdWidget(rel) 102 112 >>> print w.render('test', core.parent_id, attrs={}) 103 113 <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> <strong>Apple</strong> 114 >>> print w.render('test', child_of_hidden.parent_id, attrs={}) 115 <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> <strong>Hidden</strong> 104 116 """ % { 105 117 'ADMIN_MEDIA_PREFIX': settings.ADMIN_MEDIA_PREFIX, 106 118 'STORAGE_URL': default_storage.url(''),