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)
}}}
The image url is: https://s3.ax1x.com/2021/01/13/stTQWq.png).
--
Ticket URL: <https://code.djangoproject.com/ticket/32348>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
* component: Uncategorized => Documentation
--
Ticket URL: <https://code.djangoproject.com/ticket/32348#comment:1>
* Attachment "Snipaste_2021-01-13_12-48-24.png" added.
Old description:
New description:
[https://docs.djangoproject.com/en/3.1/intro/tutorial07/#writing-your-
first-django-app-part-7 writing-your-first-django-app-part-7]
{{{
# polls.models.py
def __str__(self):
return self.question_text
def __str__(self):
return self.choice_text
}}}
{{{
# polls.admin.py
admin.site.register(Question, QuestionAdmin)
}}}
The image is:
[[Image(Snipaste_2021-01-13_12-48-24.png)]]
--
--
Ticket URL: <https://code.djangoproject.com/ticket/32348#comment:2>
* severity: Normal => Release blocker
* cc: Carlton Gibson (added)
* component: Documentation => contrib.admin
* type: Uncategorized => Bug
* stage: Unreviewed => Accepted
Comment:
Thanks for this report. This is not an issue in docs by a regression in
24e540fbd71bd2b0843e751bde61ad0052a811b3 (see #29087). Deleting inlines
added with `extra` should not be possible.
--
Ticket URL: <https://code.djangoproject.com/ticket/32348#comment:3>
* owner: nobody => Hasan Ramezani
* status: new => assigned
--
Ticket URL: <https://code.djangoproject.com/ticket/32348#comment:4>
Comment (by Hasan Ramezani):
I just created an [https://github.com/django/django/pull/13888 initial
draft patch] which is not working. I will complete it soon.
--
Ticket URL: <https://code.djangoproject.com/ticket/32348#comment:5>
* has_patch: 0 => 1
--
Ticket URL: <https://code.djangoproject.com/ticket/32348#comment:6>
Comment (by Hasan Ramezani):
Now it is ready for review. I am not sure about the logic in
`toggleDeleteButtonVisibility` function
--
Ticket URL: <https://code.djangoproject.com/ticket/32348#comment:7>
Comment (by Guan):
Replying to [comment:7 Hasan Ramezani]:
> Now it is ready for review. I am not sure about the logic in
`toggleDeleteButtonVisibility` function
Hi! Thanks for your work. But there are probably two slight flaws I think:
1. 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.
2. For {{{toggleDeleteButtonVisibility}}} function, my option comes from
[https://docs.djangoproject.com/en/3.1/intro/tutorial07/ **extra** form
could not be removed] and
[https://docs.djangoproject.com/en/3.1/topics/forms/formsets/ 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 [https://github.com/hramezani/django/pull/1 PR] and I'd
like to know your option.
--
Ticket URL: <https://code.djangoproject.com/ticket/32348#comment:8>
Comment (by Hasan Ramezani):
Thanks Guan for the new calculation. I added your patch to my PR as
separate commiet
--
Ticket URL: <https://code.djangoproject.com/ticket/32348#comment:9>
Comment (by Carlton Gibson):
Reviewing, I think we just missed a doc change with
24e540fbd71bd2b0843e751bde61ad0052a811b3. I've suggest a
[https://github.com/django/django/pull/13936 new PR] making that change.
--
Ticket URL: <https://code.djangoproject.com/ticket/32348#comment:10>
* owner: Hasan Ramezani => Carlton Gibson
* component: contrib.admin => Documentation
* severity: Release blocker => Normal
* stage: Accepted => Ready for checkin
Comment:
Having conferred with Mariusz, we will go with the documentation change.
Thanks all.
--
Ticket URL: <https://code.djangoproject.com/ticket/32348#comment:11>
* status: assigned => closed
* resolution: => fixed
Comment:
In [changeset:"f4272d000af598018247fe9687dac0fd02a29a7c" f4272d00]:
{{{
#!CommitTicketReference repository=""
revision="f4272d000af598018247fe9687dac0fd02a29a7c"
Fixed #32348, Refs #29087 -- Corrected tutorial for updated deleting
inlines UI.
Updated tutorial to match change in
24e540fbd71bd2b0843e751bde61ad0052a811b3
allowing deletion of original extra inlines.
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/32348#comment:12>
Comment (by Carlton Gibson <carlton.gibson@…>):
In [changeset:"4dbbe3747955cbecbf3668c93a0c885562f063ac" 4dbbe37]:
{{{
#!CommitTicketReference repository=""
revision="4dbbe3747955cbecbf3668c93a0c885562f063ac"
[3.2.x] Fixed #32348, Refs #29087 -- Corrected tutorial for updated
deleting inlines UI.
Updated tutorial to match change in
24e540fbd71bd2b0843e751bde61ad0052a811b3
allowing deletion of original extra inlines.
Backport of f4272d000af598018247fe9687dac0fd02a29a7c from master
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/32348#comment:13>
Comment (by Carlton Gibson <carlton.gibson@…>):
In [changeset:"fa203f17591d53178c28b20f9ad337812666445d" fa203f17]:
{{{
#!CommitTicketReference repository=""
revision="fa203f17591d53178c28b20f9ad337812666445d"
[3.1.x] Fixed #32348, Refs #29087 -- Corrected tutorial for updated
deleting inlines UI.
Updated tutorial to match change in
24e540fbd71bd2b0843e751bde61ad0052a811b3
allowing deletion of original extra inlines.
Backport of f4272d000af598018247fe9687dac0fd02a29a7c from master
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/32348#comment:14>