Ticket #14982: empty_changelist_value.patch
File empty_changelist_value.patch, 2.9 KB (added by , 14 years ago) |
---|
-
django/contrib/admin/templatetags/admin_list.py
155 155 else: 156 156 if value is None: 157 157 result_repr = EMPTY_CHANGELIST_VALUE 158 if isinstance(f.rel, models.ManyToOneRel):158 elif isinstance(f.rel, models.ManyToOneRel): 159 159 result_repr = escape(getattr(result, f.name)) 160 160 else: 161 161 result_repr = display_for_field(value, f) -
tests/regressiontests/admin_changelist/tests.py
20 20 m.list_select_related, m.list_per_page, m.list_editable, m) 21 21 self.assertEqual(cl.query_set.query.select_related, {'parent': {'name': {}}}) 22 22 23 def test_result_list_empty_changelist_value(self): 24 """ 25 Regression test for #14982: EMPTY_CHANGELIST_VALUE should be honored 26 for relationship fields 27 """ 28 new_child = Child.objects.create(name='name', parent=None) 29 request = MockRequest() 30 m = ChildAdmin(Child, admin.site) 31 cl = ChangeList(request, Child, m.list_display, m.list_display_links, 32 m.list_filter, m.date_hierarchy, m.search_fields, 33 m.list_select_related, m.list_per_page, m.list_editable, m) 34 cl.formset = None 35 template = Template('{% load admin_list %}{% spaceless %}{% result_list cl %}{% endspaceless %}') 36 context = Context({'cl': cl}) 37 table_output = template.render(context) 38 row_html = '<tbody><tr class="row1"><td><input type="checkbox" class="action-select" value="1" name="_selected_action" /></td><th><a href="1/">name</a></th><td>(None)</td></tr></tbody>' 39 self.assertFalse(table_output.find(row_html) == -1, 40 'Failed to find expected row element: %s' % table_output) 41 42 23 43 def test_result_list_html(self): 24 44 """ 25 45 Verifies that inclusion tag result_list generates a table when with -
tests/regressiontests/admin_changelist/models.py
5 5 name = models.CharField(max_length=128) 6 6 7 7 class Child(models.Model): 8 parent = models.ForeignKey(Parent, editable=False) 9 name = models.CharField(max_length=30, blank=True) 10 No newline at end of file 8 parent = models.ForeignKey(Parent, editable=False, null=True) 9 name = models.CharField(max_length=30, blank=True)