Skip to content

Conversation

@byrn-baker
Copy link

Closes: Add tenant attribute to AutonomousSystem model #191

What's Changed

Add a ForeignKey field for Tenant to the AutonomousSystem model, update the forms.py and autonomoussystemrange_retrieve.html to reference the Tenant field for display and input.

image
image
image

To Do

  • [ x] Explanation of Change(s)
  • Added change log fragment(s) (for more information see the documentation)
  • [ x] Attached Screenshots, Payload Example
  • Unit, Integration Tests
  • Documentation Updates (when adding/changing features)
  • Outline Remaining Work, Constraints from Design

Copy link
Contributor

@glennmatthews glennmatthews left a comment

Choose a reason for hiding this comment

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

Thanks!

class Meta:
model = models.AutonomousSystem
fields = ("asn", "description", "provider", "status", "tags")
fields = ("asn", "description", "tenant", "provider", "status", "tags")
Copy link
Contributor

Choose a reason for hiding this comment

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

I'd suggest using TenancyForm as a mixin on the form class, which will automatically add the relevant form fields.

fields = ("asn", "description", "tenant", "provider", "status", "tags")


class AutonomousSystemFilterForm(NautobotFilterForm):
Copy link
Contributor

@glennmatthews glennmatthews Feb 27, 2025

Choose a reason for hiding this comment

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

Similarly, please add TenancyFilterForm to this form class. You'll also need to update the AutonomousSystemFilterSet with the TenancyModelFilterSetMixin mixin class to support filtering by tenant.

@glennmatthews
Copy link
Contributor

Maybe also add an appropriate TenantColumn to the AutonomousSystem Table class?

@byrn-baker
Copy link
Author

I will take a look at the above and make those updates.

@byrn-baker
Copy link
Author

Updated the code to this PR. Let me know if this is what you were requesting. One minor update to the models under AutonomousSytem for the tenant field was to include a related_name.

"description": "icontains",
},
)
tenant = django_filters.ModelMultipleChoiceFilter(
Copy link
Contributor

Choose a reason for hiding this comment

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

Possible to use nautobot.tenancy.filters.mixins.TenancyModelFilterSetMixin instead of this explicit declaration?

Comment on lines +37 to +42
tenant = tables.LinkColumn(
viewname="tenancy:tenant",
args=[A("tenant__pk")],
verbose_name="Tenant",
text=lambda record: record.tenant.name if record.tenant else "",
)
Copy link
Contributor

Choose a reason for hiding this comment

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

Is all this configuration needed? I would have thought tenant = tables.Column(linkify=True) would work just as well.

Copy link
Contributor

@smk4664 smk4664 Mar 3, 2025

Choose a reason for hiding this comment

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

We have TenantColumn as well.

from nautobot.tenancy.tables import TenantColumn


...

tenant = TenantColumn()

@mzbroch
Copy link
Contributor

mzbroch commented Mar 4, 2025

Please update unit tests too.

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.

5 participants