Ticket #11607: 11607.diff
File 11607.diff, 2.8 KB (added by , 15 years ago) |
---|
-
django/contrib/admin/widgets.py
147 147 148 148 def label_for_value(self, value): 149 149 key = self.rel.get_related_field().name 150 obj = self.rel.to._default_manager.get(**{key: value}) 151 return ' <strong>%s</strong>' % truncate_words(obj, 14) 150 try: 151 obj = self.rel.to._default_manager.get(**{key: value}) 152 label = ' <strong>%s</strong>' % truncate_words(obj, 14) 153 except self.rel.to.DoesNotExist: 154 label = '' 155 return label 152 156 153 157 class ManyToManyRawIdWidget(ForeignKeyRawIdWidget): 154 158 """ -
tests/regressiontests/admin_widgets/urls_rawid.py
1 2 from django.conf.urls.defaults import * 3 import rawidadmin 4 5 urlpatterns = patterns('', 6 (r'^rawid_admin/', include(rawidadmin.site.urls)), 7 ) -
tests/regressiontests/admin_widgets/rawidadmin.py
1 """ 2 3 """ 4 from django.contrib import admin 5 6 import models 7 8 class RawIdAdmin(admin.AdminSite): 9 pass 10 11 class CarAdmin(admin.ModelAdmin): 12 raw_id_fields = ['owner'] 13 14 site = RawIdAdmin(name='rawid-admin') 15 16 site.register(models.User) 17 site.register(models.Car, CarAdmin) -
tests/regressiontests/admin_widgets/tests.py
130 130 class OldAdminForeignKeyWidgetChangeList(AdminForeignKeyWidgetChangeList): 131 131 urls = 'regressiontests.admin_widgets.urls2' 132 132 admin_root = '/deep/down/admin' 133 134 class AdminForeignKeyRawIdWidgetInvalidId(DjangoTestCase): 135 urls = 'regressiontests.admin_widgets.urls_rawid' 136 fixtures = ["admin-widgets-users.xml"] 137 admin_root = '/rawid_admin' 138 139 def setUp(self): 140 self.client.login(username="super", password="secret") 141 142 def tearDown(self): 143 self.client.logout() 144 145 def test_invalid_id(self): 146 response = self.client.post('%s/admin_widgets/car/add/' % self.admin_root, 147 {'owner': '999', # does not exist 148 'make': 'VW', 149 'model': 'Karmann Ghia'}) 150 self.assertEqual(response.status_code, 200)