Package: django-clone
PythonDjangoDownloadsCode StylePyPITestVulnerabilitiesCoverageCode QualityPre-Commitdjango-cloneCreate copies of a model instance with explicit control on how the instance should be duplicated (limiting fields or related objects copied) with unique field detection.This solves the problem introduced by usinginstance.pk = Noneandinstance.save()which results in copying more object state than required.Features100% test coverage.More control over how a model instance should be duplicatedMulti Database support i.e Create duplicates on one or more databases.Restrict fields used for creating a duplicate instance.Detects unique fields and naively adds a suffixcopy {count}to each duplicate instance (for supported fields only).Optionally differentiate between a duplicate instance and the original by appending acopysuffix to non unique fields (for supported fields only).Table of ContentsInstallationpippoetryUsageSubclassing theCloneModelUsing theCloneMixinDuplicating a model instanceBulk cloning a modelCreating clones without subclassingCloneMixin.CloneMixin attributesExplicit (include only these fields)Implicit (include all except these fields)Django AdminDuplicating Models from the Django Admin view.List ViewChange ViewCloneModelAdmin class attributesAdvanced UsageSignalspre_clone_save, post_clone_saveClone Many to Many fieldsUsing theCloneModelUsing theCloneMixinMulti database supportCompatibilityRunning locallyFound a Bug?Contributors ✨Installationpippipinstalldjango-clonepoetrypoetryadddjango-cloneUsageSubclassing theCloneModelUsing theCloneMixinDuplicating a model instanceBulk cloning a modelCreating clones without subclassingCloneMixin.NOTE::warning:This method won't copy over related objects like Many to Many/One to Many relationships.Ensure that required fields skipped from being cloned are passed in using theattrskwargs.CloneMixin attributesAttributeDescriptionDUPLICATE_SUFFIXSuffix to append to duplicates(NOTE: This requiresUSE_DUPLICATE_SUFFIX_FOR_NON_UNIQUE_FIELDSto be enabled and supports string fields).USE_DUPLICATE_SUFFIX_FOR_NON_UNIQUE_FIELDSEnable appending theDUPLICATE_SUFFIXto new cloned instances.UNIQUE_DUPLICATE_SUFFIXSuffix to append to unique fieldsUSE_UNIQUE_DUPLICATE_SUFFIXEnable appending theUNIQUE_DUPLICATE_SUFFIXto new cloned instances.MAX_UNIQUE_DUPLICATE_QUERY_ATTEMPTSThe max query attempt while generating unique values for a case of unique conflicts.Explicit (include only these fields)AttributeDescription_clone_fieldsRestrict the list of fields to copy from the instance (By default: Copies all fields excluding auto-created/non editable model fields)_clone_m2m_fieldsRestricted Many to many fields (i.e Test.tags)_clone_m2o_or_o2m_fieldsRestricted Many to One/One to Many fields_clone_o2o_fieldsRestricted One to One fields_clone_linked_m2m_fieldsRestricted Many to Many fields that should be linked to the new instanceImplicit (include all except these fields)AttributeDescription_clone_excluded_fieldsExcluded model fields._clone_excluded_m2m_fieldsExcluded many to many fields._clone_excluded_m2o_or_o2m_fieldsExcluded Many to One/One to Many fields._clone_excluded_o2o_fieldsExcluded one to one fields.NOTE::warning:Ensure to either set_clone_excluded_*or_clone_*. Using both would raise errors.Django AdminDuplicating Models from the Django Admin view.List ViewChange ViewCloneModelAdmin class attributesNOTE::warning:Ensure thatmodel_cloneis placed beforedjango.contrib.adminINSTALLED_APPS=['model_clone','django.contrib.admin','...',]Advanced UsageSignalspre_clone_save, post_clone_saveClone Many to Many fieldsUsing theCloneModelUsing theCloneMixinMulti database supportCompatibilityPythonSupported versionPython2.x<=2.5.3Python3.5<=2.9.6Python3.6+All versionsDjangoSupported version1.11<=2.7.22.xAll versions3.xAll versionsRunning locally$gitclonegit@github.com:tj-django/django-clone.git
$makedefault-user
$makerunSpins up a django server running the demo app.Visithttp://127.0.0.1:8000Found a Bug?To file a bug or submit a patch, please head over todjango-clone on github.If you feel generous and want to show some extra appreciation:Support me with a :star:Contributors ✨Thanks goes to these wonderful people:Gerben Neven🐛⚠️💻Sebastian Kapunkt💻🐛⚠️Andrés Portillo🐛WhiteSource Renovate🚧Yuekui💻🐛⚠️📖🚧Take Weiland⚠️🐛💻Patrick🐛💻Amiel Kollek💻🐛⚠️Eric Theise📖Daniel Schaffer💻⚠️This project follows theall-contributorsspecification. Contributions of any kind welcome!