Opened 13 years ago
Closed 12 years ago
#19082 closed Cleanup/optimization (fixed)
Improve the prepopulated_fields autocompletion logic
| Reported by: | Manuel Saelices | Owned by: | micaelwidell |
|---|---|---|---|
| Component: | contrib.admin | Version: | 1.4 |
| Severity: | Normal | Keywords: | |
| Cc: | d1fffuz0r@… | Triage Stage: | Accepted |
| Has patch: | yes | Needs documentation: | no |
| Needs tests: | no | Patch needs improvement: | no |
| Easy pickings: | yes | UI/UX: | no |
Description
I think the logic behind prepopulated fields in admin sould be improved.
The current condition to decide whether to autocomplete the field is: I autocomplete if we are adding the object and it is not already changed by the user.
The problem I found is the we are adding the object part of the previous condition. I think is useful not worry about the add/edit context. I prefer the condition I autocomplete if the field is not already changed by the user and it is empty when the page is loaded
I suppose the current logic is valid because most times the prepopulated fields are SlugField instances, which are usually required. This implies they cannot be empty when we are editing the object (because it was already added with a non empty value). But this is not a required precondition, because you can use the following model and model admin:
# models.py class Person(models.Model): name = models.CharField(max_length=200, null=True, blank=True) surname = models.CharField(...) nickname = models.SlugField(null=True, blank=True) # admin.py class PersonAdmin(admin.ModelAdmin): prepopulated_fields = {"nickname": ("name",)}
Attachments (2)
Change History (7)
by , 13 years ago
| Attachment: | better_prepopulated_fields_logic.diff added |
|---|
comment:1 by , 13 years ago
| Triage Stage: | Unreviewed → Accepted |
|---|
Agreed. Could you write some Selenium tests for this? You can find an example in django.tests.regressiontests.admin_views.tests.SeleniumPrePopulatedFirefoxTests.
comment:2 by , 13 years ago
| Owner: | changed from to |
|---|---|
| Status: | new → assigned |
comment:3 by , 13 years ago
| Needs tests: | set |
|---|
by , 13 years ago
| Attachment: | better_prepopulated_fields_logic_with_tests.diff added |
|---|
upgrade the patch. added test
comment:4 by , 13 years ago
| Cc: | added |
|---|---|
| Needs tests: | unset |
comment:5 by , 12 years ago
| Resolution: | → fixed |
|---|---|
| Status: | assigned → closed |
Better autocompletion logic