#16838 closed Bug (fixed)
First InlineModelAdmin not displaying "Add Another" link when related_name='+'
Reported by: | jamesp | Owned by: | nobody |
---|---|---|---|
Component: | contrib.admin | Version: | dev |
Severity: | Normal | Keywords: | |
Cc: | Triage Stage: | Accepted | |
Has patch: | yes | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
The first InlineModelAdmin displayed in a ModelAdmin subclass does not show the "Add Another" link.
The admin HTML code that gets generated for inlines appears to be inconsistent (for example, the generated HTML has id="id_MAX_FORMS"
while the inlines jQuery is looking for #id_-MAX_FORMS
).
Attachments (3)
Change History (11)
comment:1 by , 13 years ago
Resolution: | → worksforme |
---|---|
Status: | new → closed |
comment:2 by , 13 years ago
Resolution: | worksforme |
---|---|
Status: | closed → reopened |
I got your results with the code above and realized I needed to provide more information about my models.
If you set up the ForeignKeys with related_name='+', then you get the behavior I described:
from django.db import models class Author(models.Model): name = models.CharField(max_length=100) class Subject(models.Model): name = models.CharField(max_length=100, related_name='+') author = models.ForeignKey(Author) class Book(models.Model): title = models.CharField(max_length=100, related_name='+') author = models.ForeignKey(Author)
by , 13 years ago
Attachment: | inlines-add_another-missing.png added |
---|
"Add another" link missing with related_name='+' in ForeignKey
comment:3 by , 13 years ago
Summary: | First InlineModelAdmin not displaying "Add Another" link → First InlineModelAdmin not displaying "Add Another" link when related_name='+' |
---|
comment:4 by , 13 years ago
Triage Stage: | Unreviewed → Accepted |
---|
Verified. Note that related_name
actually should be on the FKs, not the CharFields ;-) Thanks for the report!
comment:6 by , 13 years ago
My god, I am a mess. You're right, it should be on the ForeignKeys.
I need some damn sleep. :P
by , 13 years ago
Attachment: | t16838-inlines_tests.diff added |
---|
Tests to pass for admin inlines with related_name='+'
comment:7 by , 13 years ago
Has patch: | set |
---|
What's occurring here is that related_name='+' causes the form prefix to be blank. This causes issues for inlines because the first item comes through with an entirely blank prefix. This behavior breaks the admin Javascript.
The attached patch passes the regression tests, as best I can tell.
Using the following models.py and admin.py on trunk Django, I get "add another" links for both book and subject when I add/edit an author.
models.py:
admin.py: