Skip to content

Is it safe to use .validated_save() when duplicating objects? #4558

Answered by jathanism
rlad78 asked this question in Q&A
Discussion options

You must be logged in to vote

I would recommend not doing this and instead being more declarative in exactly which fields you would like to carry over in a new instance, for example:

    def new_member(self, head_device: dcim_m.Device, ... ) -> dcim_m.Device:
        ....

         # Explicitly declare the other fields you want from head_device here
        head_device_fork = dcim_m.Device(
            name=head_device.name,
            asset_tag=head_device.asset_tag,
            # etc...
        )
      
        # The rest of this still applies since this is also declarative
        if head_device.virtual_chassis is not None:
            head_device_fork.vc_position = member_number
            head_device_fork.vc_pr…

Replies: 1 comment 3 replies

Comment options

You must be logged in to vote
3 replies
@rlad78
Comment options

@glennmatthews
Comment options

@rlad78
Comment options

Answer selected by rlad78
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants