Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add class variable USE_UNIQUE_DUPLICATE_SUFFIX #14

Merged

Conversation

andresp99999
Copy link
Contributor

@andresp99999 andresp99999 commented Nov 8, 2019

Hello, I have the following use case:

a) I have an object with a string field (uuid) that is stored in a 36 character field.
b) I want to use django-clone to create copies of it (including the uuid), however the current implementation append the UNIQUE_DUPLICATE_SUFFIX field and hence the value is larger than the max field size and the save() call fails.

This PR adds a class variable USE_UNIQUE_DUPLICATE_SUFFIX to disable this behavior.

@@ -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.

@jackton1 jackton1 merged commit a3c409c into tj-django:master Nov 9, 2019
@jackton1
Copy link
Member

jackton1 commented Nov 9, 2019

@all-contributors please add @andresp99999 for bugs.

@allcontributors
Copy link
Contributor

@jackton1

I've put up a pull request to add @andresp99999! 🎉

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants