#2259: Primary keys should be readonly by default in admin -------------------------------+-------------------------------------- Reporter: ed@… | Owner: Jason Hall Type: Bug | Status: assigned Component: contrib.admin | Version: dev Severity: Normal | Resolution: Keywords: | Triage Stage: Accepted Has patch: 0 | Needs documentation: 0 Needs tests: 0 | Patch needs improvement: 0 Easy pickings: 0 | UI/UX: 0 -------------------------------+-------------------------------------- Comment (by nezhar):
There is an additional issue when changing to an existing PK: the data will be saved to the PK item used in the form, leaving the original item (from the URL path) untouched. Using `Save and continue editing` compounds this issue further. The URL will not change, so the success notification will show the item that was actually modified, but the 'view' link in the notification will still point to the original entry from the URL path. For example: if editing `/pk1/change` and changing the PK to pk2 (existing) in the form, the data saves to pk2, but the URL remains `/pk1/chage`, and the data of pk1 is reloaded in the form. The notification shows pk2 was updated, the item links however to pk1. The workaround mentioned in comment 26 still works to disable the PK field in the admin when editing existing objects: {{{ @admin.register(MyModel) class MyModelAdmin(admin.ModelAdmin): def get_readonly_fields(self, request, obj=None): if obj is None: return self.readonly_fields return self.readonly_fields + (self.opts.pk.attname, ) }}} -- Ticket URL: <https://code.djangoproject.com/ticket/2259#comment:54> Django <https://code.djangoproject.com/> The Web framework for perfectionists with deadlines. -- You received this message because you are subscribed to the Google Groups "Django updates" group. To unsubscribe from this group and stop receiving emails from it, send an email to django-updates+unsubscr...@googlegroups.com. To view this discussion visit https://groups.google.com/d/msgid/django-updates/010701984f8d63f6-a93d8a68-4083-4076-9092-26610ab3cdcb-000000%40eu-central-1.amazonses.com.