Skip to content
This repository has been archived by the owner on Mar 6, 2023. It is now read-only.

_clone_copy_fk added to allow copying many-to-one relationships. #7

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

JoshBone
Copy link

@JoshBone JoshBone commented Sep 6, 2017

Hi,

In a recent project I needed to clone django models (they will act as data entry templates, that a user can make, and new records can be created based on these templates). I liked the CloneableMixin a lot, but I needed many-to-one related objects (models with ForeignKeys pointing to the source model) to be copied as well.

I've added a new function _clone_copy_fk to achieve this. What it does is that it iterates through all the related objects, removes the primary_key, changes the ForeignKey value to point to the duplicated record and bulk_create these new related records.

Regards,
Josh

…ships (records with ForeignKey pointing to the source model).
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant