Skip to content

Adding inline M2M fields#728

Merged
joewesch merged 4 commits intodevelopfrom
u/joewesch-inline-m2m-fields
Apr 27, 2026
Merged

Adding inline M2M fields#728
joewesch merged 4 commits intodevelopfrom
u/joewesch-inline-m2m-fields

Conversation

@joewesch
Copy link
Copy Markdown
Contributor

@joewesch joewesch commented Apr 13, 2026

First off, I'm sorry for the extra lengthy PR. This has been a personal hackathon project that I've been working on for the last month or so and I think it's going to be something many people will want.

This PR introduces a framework for implementing inline M2M fields on parent modules. This replaces the need to separately create (for example) clusters, devices and device to cluster associations. Now, you can create the cluster and then associate it to the device as part of the device module:

  networktocode.nautobot.device:
    ...
    clusters:
      state: merge
      objects:
        - cluster: "Test Cluster 2"

You can also now create Select and Multi-Select custom fields with the choices all with one module:

  networktocode.nautobot.custom_field:
    ...
    type: select
    custom_field_choices:
      state: replace
      objects:
        - value: "Choice A"
          weight: 100

Each of these M2M associations support their own independent state: merge (default), replace or delete. The rest of the module remains 100% the same and backwards compatible.

As part of this PR, I have deprecated all existing modules that solely made these M2M associations. Once this is merged in, I plan to add any missing M2M associations that haven't been implemented yet or anything else that may benefit from this new framework (e.g., #370, #624, #716).

Comment thread docs/getting_started/contributing/modules/architecture.md
Comment on lines +191 to +195
is_destination:
description:
- Mark the IP address as a destination IP address.
required: false
type: bool
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Is this something from firewall models? I'm not quite following this.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

These exist in the data model but aren't really fully baked at this time (i.e. they don't actually do anything) and aren't (IIRC) exposed in the UI either.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Ah, ok I was unaware they weren't really being used. I was mostly going based on the serializer and showing up in the API Schema:

Screenshot 2026-04-15 at 8 21 08 AM

I can remove them.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

I don't think it hurts to include them, my comment was more of just an FYI.

@joewesch joewesch marked this pull request as ready for review April 15, 2026 15:13
@joewesch joewesch requested review from a team and jmcgill298 as code owners April 15, 2026 15:13
@joewesch joewesch changed the title [Draft] Added inline M2M fields Adding inline M2M fields Apr 15, 2026
# Used by parent modules to declare inline M2M / child-object fields.
# Keys match self.endpoint values (plural API endpoint names).
# Values are the API endpoint name to manage the association/assignment.
M2M_FIELDS = {
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Note for reviewers: if you only have time to thoroughly review one file it should be this file. This is where almost all of the new logic lives. The rest of the files are primarily the field definitions and tests.

Copy link
Copy Markdown
Contributor

@gsnider2195 gsnider2195 left a comment

Choose a reason for hiding this comment

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

I didn't see any problems in the module utils. I admit that I didn't understand some of the field name mappings.

@joewesch joewesch merged commit db9b419 into develop Apr 27, 2026
21 checks passed
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.

4 participants