#32348 closed Bug (fixed)
Deleting "extra" inlines in admin should not be possible.
| Reported by: | Guan | Owned by: | Carlton Gibson |
|---|---|---|---|
| Component: | Documentation | Version: | 3.1 |
| Severity: | Normal | Keywords: | |
| Cc: | Carlton Gibson | Triage Stage: | Ready for checkin |
| Has patch: | yes | Needs documentation: | no |
| Needs tests: | no | Patch needs improvement: | no |
| Easy pickings: | no | UI/UX: | no |
Description (last modified by )
writing-your-first-django-app-part-7
There is a description: Note that you can’t remove the original three slots.
But I find that the original three slots is able to be removed in Django 3.1.5. The code is as follows:
# polls.models.py
class Question(models.Model):
question_text = models.CharField(max_length=200)
pub_date = models.DateTimeField(verbose_name="date published")
def __str__(self):
return self.question_text
def was_published_recently(self):
now = timezone.now()
return now >= self.pub_date >= now - datetime.timedelta(days=1)
class Choice(models.Model):
question = models.ForeignKey(Question, on_delete=models.CASCADE)
choice_text = models.CharField(max_length=200)
votes = models.IntegerField(default=0)
def __str__(self):
return self.choice_text
# polls.admin.py
class ChoiceInline(admin.StackedInline):
model = Choice
extra = 3
class QuestionAdmin(admin.ModelAdmin):
# fields = ["pub_date", "question_text"]
fieldsets = [
(None, {"fields": ["question_text"]}),
("Date Information", {"fields": ["pub_date"]})
]
inlines = [ChoiceInline]
admin.site.register(Question, QuestionAdmin)
Attachments (1)
Change History (15)
comment:1 by , 5 years ago
| Component: | Uncategorized → Documentation |
|---|
by , 5 years ago
| Attachment: | Snipaste_2021-01-13_12-48-24.png added |
|---|
comment:2 by , 5 years ago
| Description: | modified (diff) |
|---|
comment:3 by , 5 years ago
| Cc: | added |
|---|---|
| Component: | Documentation → contrib.admin |
| Severity: | Normal → Release blocker |
| Summary: | Error description of Django document in "tutorial07" → Deleting "extra" inlines in admin should not be possible. |
| Triage Stage: | Unreviewed → Accepted |
| Type: | Uncategorized → Bug |
comment:4 by , 5 years ago
| Owner: | changed from to |
|---|---|
| Status: | new → assigned |
comment:5 by , 5 years ago
I just created an initial draft patch which is not working. I will complete it soon.
comment:6 by , 5 years ago
| Has patch: | set |
|---|
follow-up: 8 comment:7 by , 5 years ago
Now it is ready for review. I am not sure about the logic in toggleDeleteButtonVisibility function
comment:8 by , 5 years ago
Replying to Hasan Ramezani:
Now it is ready for review. I am not sure about the logic in
toggleDeleteButtonVisibilityfunction
Hi! Thanks for your work. But there are probably two slight flaws I think:
- When ValidationError is raised, it's no 'X' at the top right of form. That the UX is not comfortable is ticket #29087 talked about.
- For
toggleDeleteButtonVisibilityfunction, my opinion comes from **extra** form could not be removed and if a formset contains no data, then extra + min_num empty forms will be displayed. So the calculation I think is:const isFormOverload = function() { const totalFormNum = ~~totalForms.val(); const initialFormNum = ~~initialForms.val(); const minFormNum = ~~minForms.val(); const extraFormNum = ~~extraForms.val(); const emptyFormNum = totalFormNum - initialFormNum; if (initialFormNum >= emptyFormNum) { return emptyFormNum > extraFormNum; } return emptyFormNum > extraFormNum + minFormNum - initialFormNum; }
When isFormOverload returns true, all forms show 'X'.
I created patch PR and I'd like to know your opinion.
comment:9 by , 5 years ago
Thanks Guan for the new calculation. I added your patch to my PR as separate commiet
comment:10 by , 5 years ago
Reviewing, I think we just missed a doc change with 24e540fbd71bd2b0843e751bde61ad0052a811b3. I've suggest a new PR making that change.
comment:11 by , 5 years ago
| Component: | contrib.admin → Documentation |
|---|---|
| Owner: | changed from to |
| Severity: | Release blocker → Normal |
| Triage Stage: | Accepted → Ready for checkin |
Having conferred with Mariusz, we will go with the documentation change. Thanks all.

Thanks for this report. This is not an issue in docs by a regression in 24e540fbd71bd2b0843e751bde61ad0052a811b3 (see #29087). Deleting inlines added with
extrashould not be possible.