#9765 closed (worksforme)
admin: Inline saves extras when model has choices and a default choice
Reported by: | Roland van Laar | Owned by: | nobody |
---|---|---|---|
Component: | contrib.admin | Version: | 1.0 |
Severity: | Keywords: | admin inline choices save | |
Cc: | rick@… roland@… | Triage Stage: | Unreviewed |
Has patch: | no | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
When having defined choices and a default such as:
Class Node: status = models.CharField(max_length=10, choices=STATUS_CHOICES, default=1) another_field = models.CharField(max_length=10)
and in the admin:
class NodeInline(admin.TabularInline): model = Node extra = 2
Pressing save will try to save all the extra fields as well even though no changes in the fields of the extras were made.
This leads to validation errors of the unfilled entries.
The admin should know that nothing has changed and not try to save extra inline field that weren't edited.
Change History (2)
comment:1 by , 16 years ago
Resolution: | → worksforme |
---|---|
Status: | new → closed |
comment:2 by , 16 years ago
You are correct.
My status choices were:
STATUS_CHOICES = ( ('up', 'up'), ('dw', 'down'), ('pl', 'planned'), )
It should indeed be a character, instead of an integer. It works when I change default to 'up'.
Class Node(models.Model): status = models.CharField(max_length=10, choices=STATUS_CHOICES, default='up') another_field = models.CharField(max_length=10)
Note:
See TracTickets
for help on using tickets.
Admin tries to save new entries when the submitted values differ from the initial ones. I'm guessing there's something wrong with your default= specification, but I'm not sure what since you didn't include your definition of STATUS_CHOICES -- hmm, since it's a char field perhaps it ought to be '1' instead of 1. At any rate I know from experience this does work in admin, so there is something wrong with how you have specified it. What is coming back from the submitted form differs from the initial value you have specified, and that is why admin tries to save new entries.