#4027: Document how to make copies of model instances
-------------------------------------+-------------------------------------
Reporter: Marek | Owner: oinopion
Kubica | Status: assigned
Type: New | Component: Documentation
feature | Severity: Normal
Milestone: | Keywords: db, copy
Version: SVN | Has patch: 1
Resolution: | Needs tests: 0
Triage Stage: Ready for | Easy pickings: 0
checkin |
Needs documentation: 0 |
Patch needs improvement: 0 |
UI/UX: 0 |
-------------------------------------+-------------------------------------
Changes (by bruth):
* cc: bruth@… (added)
Comment:
I tackled this problem as a separate app: https://github.com/cbmi/django-
forkit. It is simply an abstract model that implements a few methods such
as `fork`, `reset`, and `diff`. It handles all three relationship types,
though there are a few known issues (e.g. M2M through models are not yet
supported). Deep `diff`ing is not yet fully baked, and the `reset` method
must propagate that a `reset` is intended for all related objects (rather
than creating new ones). Saving related objects are deferred until the
whole hierarchy has been traversed to ensure data integrity (and provides
ways of altering the objects post `fork`/`reset`).
Here are the tests for it thus far: https://github.com/cbmi/django-
forkit/blob/master/forkit/tests/models.py. I would be interested in
hearing feedback on a few of the assumptions I made (e.g. which
relationships to choose for a shallow copy). And definitely send a pull
request or submit a ticket if there are more elegant ways to make use of
the Django model internals.
I am posting here only to make others aware of it, but I don't think it is
appropriate to go into Django proper.
--
Ticket URL: <https://code.djangoproject.com/ticket/4027#comment:23>
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 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.