mirror of
https://github.com/netbox-community/netbox.git
synced 2025-08-25 08:46:10 -06:00
adds tags on contact assignments #12882
This commit is contained in:
parent
bc7678c716
commit
353c2a5f15
@ -22,5 +22,6 @@
|
|||||||
{% render_field form.contact %}
|
{% render_field form.contact %}
|
||||||
{% render_field form.role %}
|
{% render_field form.role %}
|
||||||
{% render_field form.priority %}
|
{% render_field form.priority %}
|
||||||
|
{% render_field form.tags %}
|
||||||
</div>
|
</div>
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
@ -104,8 +104,8 @@ class ContactAssignmentSerializer(NetBoxModelSerializer):
|
|||||||
class Meta:
|
class Meta:
|
||||||
model = ContactAssignment
|
model = ContactAssignment
|
||||||
fields = [
|
fields = [
|
||||||
'id', 'url', 'display', 'content_type', 'object_id', 'object', 'contact', 'role', 'priority', 'created',
|
'id', 'url', 'display', 'content_type', 'object_id', 'object', 'contact', 'role', 'priority', 'tags',
|
||||||
'last_updated',
|
'created', 'last_updated',
|
||||||
]
|
]
|
||||||
|
|
||||||
@extend_schema_field(OpenApiTypes.OBJECT)
|
@extend_schema_field(OpenApiTypes.OBJECT)
|
||||||
|
@ -2,6 +2,7 @@ import django_filters
|
|||||||
from django.db.models import Q
|
from django.db.models import Q
|
||||||
from django.utils.translation import gettext as _
|
from django.utils.translation import gettext as _
|
||||||
|
|
||||||
|
from extras.filters import TagFilter
|
||||||
from netbox.filtersets import ChangeLoggedModelFilterSet, OrganizationalModelFilterSet, NetBoxModelFilterSet
|
from netbox.filtersets import ChangeLoggedModelFilterSet, OrganizationalModelFilterSet, NetBoxModelFilterSet
|
||||||
from utilities.filters import ContentTypeFilter, TreeNodeMultipleChoiceFilter
|
from utilities.filters import ContentTypeFilter, TreeNodeMultipleChoiceFilter
|
||||||
from .models import *
|
from .models import *
|
||||||
@ -100,10 +101,11 @@ class ContactAssignmentFilterSet(ChangeLoggedModelFilterSet):
|
|||||||
to_field_name='slug',
|
to_field_name='slug',
|
||||||
label=_('Contact role (slug)'),
|
label=_('Contact role (slug)'),
|
||||||
)
|
)
|
||||||
|
tag = TagFilter()
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
model = ContactAssignment
|
model = ContactAssignment
|
||||||
fields = ['id', 'content_type_id', 'object_id', 'priority']
|
fields = ['id', 'content_type_id', 'object_id', 'priority', 'tag']
|
||||||
|
|
||||||
def search(self, queryset, name, value):
|
def search(self, queryset, name, value):
|
||||||
if not value.strip():
|
if not value.strip():
|
||||||
|
@ -111,3 +111,4 @@ class ContactAssignmentFilterForm(NetBoxModelFilterSetForm):
|
|||||||
choices=ContactPriorityChoices,
|
choices=ContactPriorityChoices,
|
||||||
required=False
|
required=False
|
||||||
)
|
)
|
||||||
|
tag = TagFilterField(model)
|
||||||
|
@ -1,9 +1,10 @@
|
|||||||
from django import forms
|
from django import forms
|
||||||
|
|
||||||
|
from extras.models import Tag
|
||||||
from netbox.forms import NetBoxModelForm
|
from netbox.forms import NetBoxModelForm
|
||||||
from tenancy.models import *
|
from tenancy.models import *
|
||||||
from utilities.forms import BootstrapMixin
|
from utilities.forms import BootstrapMixin
|
||||||
from utilities.forms.fields import CommentField, DynamicModelChoiceField, SlugField
|
from utilities.forms.fields import CommentField, DynamicModelChoiceField, DynamicModelMultipleChoiceField, SlugField
|
||||||
|
|
||||||
__all__ = (
|
__all__ = (
|
||||||
'ContactAssignmentForm',
|
'ContactAssignmentForm',
|
||||||
@ -132,11 +133,15 @@ class ContactAssignmentForm(BootstrapMixin, forms.ModelForm):
|
|||||||
role = DynamicModelChoiceField(
|
role = DynamicModelChoiceField(
|
||||||
queryset=ContactRole.objects.all()
|
queryset=ContactRole.objects.all()
|
||||||
)
|
)
|
||||||
|
tags = DynamicModelMultipleChoiceField(
|
||||||
|
queryset=Tag.objects.all(),
|
||||||
|
required=False
|
||||||
|
)
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
model = ContactAssignment
|
model = ContactAssignment
|
||||||
fields = (
|
fields = (
|
||||||
'content_type', 'object_id', 'group', 'contact', 'role', 'priority',
|
'content_type', 'object_id', 'group', 'contact', 'role', 'priority', 'tags'
|
||||||
)
|
)
|
||||||
widgets = {
|
widgets = {
|
||||||
'content_type': forms.HiddenInput(),
|
'content_type': forms.HiddenInput(),
|
||||||
|
20
netbox/tenancy/migrations/0011_contactassignment_tags.py
Normal file
20
netbox/tenancy/migrations/0011_contactassignment_tags.py
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
# Generated by Django 4.1.10 on 2023-07-08 07:17
|
||||||
|
|
||||||
|
from django.db import migrations
|
||||||
|
import taggit.managers
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('extras', '0092_delete_jobresult'),
|
||||||
|
('tenancy', '0010_tenant_relax_uniqueness'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.AddField(
|
||||||
|
model_name='contactassignment',
|
||||||
|
name='tags',
|
||||||
|
field=taggit.managers.TaggableManager(through='extras.TaggedItem', to='extras.Tag'),
|
||||||
|
),
|
||||||
|
]
|
@ -4,6 +4,7 @@ from django.db import models
|
|||||||
from django.urls import reverse
|
from django.urls import reverse
|
||||||
|
|
||||||
from netbox.models import ChangeLoggedModel, NestedGroupModel, OrganizationalModel, PrimaryModel
|
from netbox.models import ChangeLoggedModel, NestedGroupModel, OrganizationalModel, PrimaryModel
|
||||||
|
from netbox.models.features import TagsMixin
|
||||||
from tenancy.choices import *
|
from tenancy.choices import *
|
||||||
|
|
||||||
__all__ = (
|
__all__ = (
|
||||||
@ -92,7 +93,7 @@ class Contact(PrimaryModel):
|
|||||||
return reverse('tenancy:contact', args=[self.pk])
|
return reverse('tenancy:contact', args=[self.pk])
|
||||||
|
|
||||||
|
|
||||||
class ContactAssignment(ChangeLoggedModel):
|
class ContactAssignment(ChangeLoggedModel, TagsMixin):
|
||||||
content_type = models.ForeignKey(
|
content_type = models.ForeignKey(
|
||||||
to=ContentType,
|
to=ContentType,
|
||||||
on_delete=models.CASCADE
|
on_delete=models.CASCADE
|
||||||
|
@ -115,6 +115,9 @@ class ContactAssignmentTable(NetBoxTable):
|
|||||||
accessor=Accessor('contact__description'),
|
accessor=Accessor('contact__description'),
|
||||||
verbose_name='Contact Description'
|
verbose_name='Contact Description'
|
||||||
)
|
)
|
||||||
|
tags = columns.TagColumn(
|
||||||
|
url_name='tenancy:contactassignment_list'
|
||||||
|
)
|
||||||
actions = columns.ActionsColumn(
|
actions = columns.ActionsColumn(
|
||||||
actions=('edit', 'delete')
|
actions=('edit', 'delete')
|
||||||
)
|
)
|
||||||
@ -123,7 +126,7 @@ class ContactAssignmentTable(NetBoxTable):
|
|||||||
model = ContactAssignment
|
model = ContactAssignment
|
||||||
fields = (
|
fields = (
|
||||||
'pk', 'content_type', 'object', 'contact', 'role', 'priority', 'contact_title', 'contact_phone',
|
'pk', 'content_type', 'object', 'contact', 'role', 'priority', 'contact_title', 'contact_phone',
|
||||||
'contact_email', 'contact_address', 'contact_link', 'contact_description', 'actions'
|
'contact_email', 'contact_address', 'contact_link', 'contact_description', 'tags', 'actions'
|
||||||
)
|
)
|
||||||
default_columns = (
|
default_columns = (
|
||||||
'pk', 'content_type', 'object', 'contact', 'role', 'priority', 'contact_email', 'contact_phone'
|
'pk', 'content_type', 'object', 'contact', 'role', 'priority', 'contact_email', 'contact_phone'
|
||||||
|
Loading…
Reference in New Issue
Block a user