#2259: PK Change creates new object instead of update
---------------------------------------------------+------------------------
Reporter: [email protected] | Owner: nobody
Status: reopened | Milestone:
Component: Database layer (models, ORM) | Version:
Resolution: | Keywords:
Stage: Accepted | Has_patch: 0
Needs_docs: 1 | Needs_tests: 0
Needs_better_patch: 1 |
---------------------------------------------------+------------------------
Changes (by mtredinnick):
* stage: Design decision needed => Accepted
Comment:
Changing the (manual) primary key intentionally creates a new object. Code
relies on that, so we cannot (and are not inclined to) change it.
Developer code that wants to update an existing row can write
`MyModel.objects.filter(pk=self.pk).update(pk=new_pk)`, for example. Forms
can do similar. In the admin interface (the place this bites people
internally), we will make a change that any changeform which has the
manual pk changed will do the update trick to avoid creating a new entry.
We can do this because the admin changelist page already knows the old pk
value (it's part of the URL, for example and, if necessary, we can add a
hidden field of the original value).
If there turns out to be other Django-shipped apps that allow editing a
manual primary key field, it should behave the same way.
--
Ticket URL: <http://code.djangoproject.com/ticket/2259#comment:16>
Django <http://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 post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/django-updates?hl=en.