Opened 11 years ago
Last modified 4 years ago
#21135 new New feature
Admin: Support for editing OneToOne related models in RELATED model
Reported by: | Jonas H. | Owned by: | nobody |
---|---|---|---|
Component: | contrib.admin | Version: | dev |
Severity: | Normal | Keywords: | |
Cc: | jonas-django@…, kitsunde@…, Petr Přikryl | Triage Stage: | Accepted |
Has patch: | no | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Pull Requests: | How to create a pull request | ||
Description ¶
Consider these models:
class Person(models.Model): address = models.OneToOneField("Address") class Organization(models.Model): address = models.OneToOneField("Address") class Building(models.Model): address = models.OneToOneField("Address")
Currently it's not possible to have a different ModelAdmin
for each of the above models because the ModelAdmin.inlines
property works a *reversed* manner.
Using the new feature would look like this (same AddressAdmin
for every model)
class AddressAdmin(admin.TabularInline): model = Address class PersonAdmin(admin.ModelAdmin): inlines = [AddressAdmin] class OrganizationAdmin(admin.ModelAdmin): inlines = [AddressAdmin] class BuildingAdmin(admin.ModelAdmin): inlines = [AddressAdmin]
or even like this (different AddressAdmin
)
class PersonAddressAdmin(admin.TabularInline): model = Address class OrganizationAddressAdmin(admin.TabularInline): model = Address class BuildingAddressAdmin(admin.TabularInline): model = Address class PersonAdmin(admin.ModelAdmin): inlines = [PersonAddressAdmin] class OrganizationAdmin(admin.ModelAdmin): inlines = [OrganizationAddressAdmin] class BuildingAdmin(admin.ModelAdmin): inlines = [BuildingAddressAdmin]
According to the ticket's flags, the next step(s) to move this issue forward are:
- To provide a patch by sending a pull request. Claim the ticket when you start working so that someone else doesn't duplicate effort. Before sending a pull request, review your work against the patch review checklist. Check the "Has patch" flag on the ticket after sending a pull request and include a link to the pull request in the ticket comment when making that update. The usual format is:
[https://github.com/django/django/pull/#### PR]
.
Change History (4)
comment:1 by , 11 years ago
Cc: | added |
---|
comment:2 by , 11 years ago
Triage Stage: | Unreviewed → Accepted |
---|---|
Version: | 1.5 → master |
comment:3 by , 9 years ago
Cc: | added |
---|
comment:4 by , 4 years ago
Cc: | added |
---|
Note:
See TracTickets
for help on using tickets.
A better solution may be to use model inheritance and proxy models to achieve what you are trying to accomplish.
Here's what Malcolm had to say in an old thread on django-users:
I agree with the above.
I also found some possible code on djangosnipppets. Tentatively accepting the ticket.