Fixed #26524 -- Fixed crash in admin change view when displaying many to many forward refs.
Thanks Tim Graham for the regression test.
This commit is contained in:
parent
f0f3de3c96
commit
e24c0a2d7c
|
@ -317,7 +317,7 @@ def _get_non_gfk_field(opts, name):
|
||||||
raise FieldDoesNotExist()
|
raise FieldDoesNotExist()
|
||||||
|
|
||||||
# Avoid coercing <FK>_id fields to FK
|
# Avoid coercing <FK>_id fields to FK
|
||||||
if field.is_relation and hasattr(field, 'attname') and field.attname == name:
|
if field.is_relation and not field.many_to_many and hasattr(field, 'attname') and field.attname == name:
|
||||||
raise FieldIsAForeignKeyColumnName()
|
raise FieldIsAForeignKeyColumnName()
|
||||||
|
|
||||||
return field
|
return field
|
||||||
|
|
|
@ -596,9 +596,13 @@ class CyclicTwo(models.Model):
|
||||||
return self.name
|
return self.name
|
||||||
|
|
||||||
|
|
||||||
|
@python_2_unicode_compatible
|
||||||
class Topping(models.Model):
|
class Topping(models.Model):
|
||||||
name = models.CharField(max_length=20)
|
name = models.CharField(max_length=20)
|
||||||
|
|
||||||
|
def __str__(self):
|
||||||
|
return self.name
|
||||||
|
|
||||||
|
|
||||||
class Pizza(models.Model):
|
class Pizza(models.Model):
|
||||||
name = models.CharField(max_length=20)
|
name = models.CharField(max_length=20)
|
||||||
|
|
|
@ -4696,6 +4696,14 @@ class ReadonlyTest(AdminFieldExtractionMixin, TestCase):
|
||||||
response = self.client.get(reverse('admin:admin_views_topping_add'))
|
response = self.client.get(reverse('admin:admin_views_topping_add'))
|
||||||
self.assertEqual(response.status_code, 200)
|
self.assertEqual(response.status_code, 200)
|
||||||
|
|
||||||
|
def test_readonly_manytomany_forwards_ref(self):
|
||||||
|
topping = Topping.objects.create(name='Salami')
|
||||||
|
pizza = Pizza.objects.create(name='Americano')
|
||||||
|
pizza.toppings.add(topping)
|
||||||
|
response = self.client.get(reverse('admin:admin_views_pizza_change', args=(pizza.pk,)))
|
||||||
|
self.assertContains(response, '<label>Toppings:</label>', html=True)
|
||||||
|
self.assertContains(response, '<p>Salami</p>', html=True)
|
||||||
|
|
||||||
def test_readonly_onetoone_backwards_ref(self):
|
def test_readonly_onetoone_backwards_ref(self):
|
||||||
"""
|
"""
|
||||||
Can reference a reverse OneToOneField in ModelAdmin.readonly_fields.
|
Can reference a reverse OneToOneField in ModelAdmin.readonly_fields.
|
||||||
|
|
Loading…
Reference in New Issue