-
Notifications
You must be signed in to change notification settings - Fork 16
Add tenant attribute to AutonomousSystem model #235
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
base: develop
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -25,10 +25,15 @@ class AutonomousSystemForm(NautobotModelForm): | |
|
|
||
| tags = DynamicModelMultipleChoiceField(queryset=Tag.objects.all(), required=False) | ||
| provider = DynamicModelChoiceField(queryset=Provider.objects.all(), required=False) | ||
| tenant = DynamicModelChoiceField( | ||
| queryset=Tenant.objects.all(), | ||
| required=False, | ||
| label="Tenant", | ||
| ) | ||
|
|
||
| class Meta: | ||
| model = models.AutonomousSystem | ||
| fields = ("asn", "description", "provider", "status", "tags") | ||
| fields = ("asn", "description", "tenant", "provider", "status", "tags") | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'd suggest using |
||
|
|
||
|
|
||
| class AutonomousSystemFilterForm(NautobotFilterForm): | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Similarly, please add |
||
|
|
@@ -37,6 +42,11 @@ class AutonomousSystemFilterForm(NautobotFilterForm): | |
| model = models.AutonomousSystem | ||
| field_order = ["status", "tag"] | ||
| tag = TagFilterField(model) | ||
| tenant = DynamicModelMultipleChoiceField( | ||
| queryset=Tenant.objects.all(), | ||
| required=False, | ||
| label="Tenant", | ||
| ) | ||
|
|
||
|
|
||
| class AutonomousSystemBulkEditForm(TagsBulkEditFormMixin, NautobotBulkEditForm): | ||
|
|
@@ -46,6 +56,11 @@ class AutonomousSystemBulkEditForm(TagsBulkEditFormMixin, NautobotBulkEditForm): | |
| queryset=models.AutonomousSystem.objects.all(), widget=forms.MultipleHiddenInput() | ||
| ) | ||
| description = forms.CharField(max_length=200, required=False) | ||
| tenant = DynamicModelChoiceField( | ||
| queryset=Tenant.objects.all(), | ||
| required=False, | ||
| label="Tenant", | ||
| ) | ||
|
|
||
| class Meta: | ||
| nullable_fields = [ | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| # Generated by Django 4.2.17 on 2025-02-26 19:23 | ||
|
|
||
| from django.db import migrations, models | ||
| import django.db.models.deletion | ||
|
|
||
|
|
||
| class Migration(migrations.Migration): | ||
|
|
||
| dependencies = [ | ||
| ('tenancy', '0009_update_all_charfields_max_length_to_255'), | ||
| ('nautobot_bgp_models', '0010_alter_autonomoussystem_status_and_more'), | ||
| ] | ||
|
|
||
| operations = [ | ||
| migrations.AddField( | ||
| model_name='autonomoussystem', | ||
| name='tenant', | ||
| field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.PROTECT, to='tenancy.tenant'), | ||
| ), | ||
| ] |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| # Generated by Django 4.2.19 on 2025-02-28 21:54 | ||
|
|
||
| from django.db import migrations, models | ||
| import django.db.models.deletion | ||
|
|
||
|
|
||
| class Migration(migrations.Migration): | ||
|
|
||
| dependencies = [ | ||
| ('tenancy', '0009_update_all_charfields_max_length_to_255'), | ||
| ('nautobot_bgp_models', '0011_autonomoussystem_tenant'), | ||
| ] | ||
|
|
||
| operations = [ | ||
| migrations.AlterField( | ||
| model_name='autonomoussystem', | ||
| name='tenant', | ||
| field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.PROTECT, related_name='autonomous_systems', to='tenancy.tenant'), | ||
| ), | ||
| ] |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -34,6 +34,12 @@ class AutonomousSystemTable(StatusTableMixin, BaseTable): | |
| pk = ToggleColumn() | ||
| asn = tables.TemplateColumn(template_code=ASN_LINK, verbose_name="ASN") | ||
| provider = tables.LinkColumn() | ||
| tenant = tables.LinkColumn( | ||
| viewname="tenancy:tenant", | ||
| args=[A("tenant__pk")], | ||
| verbose_name="Tenant", | ||
| text=lambda record: record.tenant.name if record.tenant else "", | ||
| ) | ||
|
Comment on lines
+37
to
+42
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is all this configuration needed? I would have thought
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We have TenantColumn as well. |
||
| tags = TagColumn(url_name="plugins:nautobot_bgp_models:autonomoussystem_list") | ||
| actions = ButtonsColumn(model=models.AutonomousSystem) | ||
| asn_asdot = tables.Column(accessor=A("asn_asdot"), linkify=True, order_by=A("asn"), verbose_name="ASN ASDOT") | ||
|
|
||
There was a problem hiding this comment.
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.TenancyModelFilterSetMixininstead of this explicit declaration?