Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions model_clone/mixins/clone.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ class TestModel(CloneMixin, models.Model):
_clonable_one_to_one_fields = []

UNIQUE_DUPLICATE_SUFFIX = 'copy'
USE_UNIQUE_DUPLICATE_SUFFIX = True

@property
@abc.abstractmethod
Expand Down Expand Up @@ -75,8 +76,9 @@ def _create_copy_of_instance(cls, instance):
.filter(**{'{}__startswith'.format(f.attname): value})
.count()
)
if not str(value).isdigit():
value += ' {} {}'.format(cls.UNIQUE_DUPLICATE_SUFFIX, count)
if cls.USE_UNIQUE_DUPLICATE_SUFFIX is True:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can this check use ?

if cls.USE_UNIQUE_DUPLICATE_SUFFIX:
    ...

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, done.

if not str(value).isdigit():
value += ' {} {}'.format(cls.UNIQUE_DUPLICATE_SUFFIX, count)
if isinstance(f, SlugField):
value = slugify(value)
defaults[f.attname] = value
Expand Down