#35878: Allow to add M2M also in related-model form in admin site
-----------------------+-----------------------------------------
Reporter: David | Type: Uncategorized
Status: new | Component: contrib.admin
Version: | Severity: Normal
Keywords: | Triage Stage: Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-----------------------+-----------------------------------------
Given the following definition of models:
{{{#!python
from django.db import models
class ModelA(models.Model):
name = models.CharField(max_length=10)
class ModelB(models.Model):
name = models.CharField(max_length=10)
others = models.ManyToManyField(ModelA)
}}}
The admin site allows to add the field `ModelB.others` to that model's
admin, but there is no easy way to add the same relation on `ModelA` admin
with the same functionality .
It is possible to add the field by providing a custom form in which the
related-field is defined manually, however the form field widget will not
be wrapped in `RelatedFieldWidgetWrapper` thus the "add new entry" button
will not be present. This can be forced in the `ModelAdmin.form` by
turning the `form` attribute into a property which builds the form class
providing the right parameters to the reverse-field.
It would be a great enhancement to allow for an easier way to add reverse-
m2m to a model-admin or to write down a guide to obtain such result.
--
Ticket URL: <
https://code.djangoproject.com/ticket/35878>
Django <
https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.