We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
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
id
A model with a custom id field is not duplicated:
the Branch model has the id id = models.UUIDField(primary_key=True, default=uuid4)
Branch
id = models.UUIDField(primary_key=True, default=uuid4)
>>> base_branch = Branch.objects.create(name='Main branch', parent=None, is_master=True, status=Branch.DRAFT) >>> base_branch.pk UUID('7a613f9d-90fe-4116-b897-69505cd4ff5c') >>> clone = base_branch.make_clone() >>> clone.pk UUID('7a613f9d-90fe-4116-b897-69505cd4ff5c')
I think this is because the custom id shows up in _meta.concrete_fields the value is copied over, preventing it from generating a new PK.
_meta.concrete_fields
>>> base_branch._meta.concrete_fields (<django.db.models.fields.UUIDField: id>, <django.db.models.fields.CharField: name>, <django.db.models.fields.BooleanField: is_master>, <django.db.models.fields.related.ForeignKey: parent>, <django.db.models.fields.CharField: status>)
The primary key field can be found through instance._meta.pk, filtering this out of the fields to copy should resolve this problem I think.
instance._meta.pk
The text was updated successfully, but these errors were encountered:
@all-contributors please add @gerbyzation for bug, tests and code
Sorry, something went wrong.
@jackton1
I've put up a pull request to add @gerbyzation! 🎉
Successfully merging a pull request may close this issue.
A model with a custom
id
field is not duplicated:the
Branch
model has the idid = models.UUIDField(primary_key=True, default=uuid4)
I think this is because the custom id shows up in
_meta.concrete_fields
the value is copied over, preventing it from generating a new PK.The primary key field can be found through
instance._meta.pk
, filtering this out of the fields to copy should resolve this problem I think.The text was updated successfully, but these errors were encountered: