Opened 6 years ago
Closed 6 years ago
#29894 closed New feature (wontfix)
Read-only fields in ModelAdmin should not be placed at the end
Reported by: | Jannik Schürg | Owned by: | nobody |
---|---|---|---|
Component: | contrib.admin | Version: | dev |
Severity: | Normal | Keywords: | readonly |
Cc: | Triage Stage: | Unreviewed | |
Has patch: | yes | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
Code example:
class MyModel(models.Model): prop1 = models.CharField(max_length=255) prop2 = models.CharField(max_length=255) @admin.register(MyModel) class MyModelAdmin(admin.ModelAdmin): readonly_fields = ('prop1',)
Then, in admin the field prop1
is added at the end. Especially for models with many fields and dynamic readonly fields through get_readonly_fields
the bahavior is unexpected. Instead, the read-only fields should replace their editable fields and stay in order.
Change History (3)
comment:2 by , 6 years ago
Why isn't using fieldsets
the right approach here? https://docs.djangoproject.com/en/2.1/ref/contrib/admin/index#django.contrib.admin.ModelAdmin.fieldsets
comment:3 by , 6 years ago
Resolution: | → wontfix |
---|---|
Status: | new → closed |
Hi Jannik,
Thanks for the input and the discussion on the PR.
I'm going to say no to this one as-is.
This would affect almost all users of the admin, changing a long-standing behaviour. That doesn't seem justified given that fields
and fieldsets
are already available. (Use those if you want to control ordering.)
I'm happy if you want to ask for further opinions on the DevelopersMailingList. (Personally, I quite like the existing behaviour and am used to it, so I'd be -1 on making the change there.)
I worked on this. Pull request: https://github.com/django/django/pull/10564
I should mention, that this patch also changes the behavior when fields are marked as read-only more than once. I think previously the field was then added more than once, now it is added only once!