Skip to content

Commit

Permalink
Closes #14156: Add custom field support for contact assignments
Browse files Browse the repository at this point in the history
  • Loading branch information
jeremystretch committed Nov 9, 2023
1 parent ac91d4e commit 2562c87
Show file tree
Hide file tree
Showing 7 changed files with 35 additions and 13 deletions.
7 changes: 7 additions & 0 deletions netbox/templates/tenancy/contactassignment_edit.html
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,11 @@ <h5 class="offset-sm-3">{% trans "Contact Assignment" %}</h5>
{% render_field form.priority %}
{% render_field form.tags %}
</div>

<div class="field-group mb-5">
<div class="row mb-2">
<h5 class="offset-sm-3">{% trans "Custom Fields" %}</h5>
</div>
{% render_custom_fields form %}
</div>
{% endblock %}
2 changes: 1 addition & 1 deletion netbox/tenancy/api/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ class Meta:
model = ContactAssignment
fields = [
'id', 'url', 'display', 'content_type', 'object_id', 'object', 'contact', 'role', 'priority', 'tags',
'created', 'last_updated',
'custom_fields', 'created', 'last_updated',
]

@extend_schema_field(OpenApiTypes.OBJECT)
Expand Down
5 changes: 2 additions & 3 deletions netbox/tenancy/filtersets.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,10 @@
from django.utils.translation import gettext as _

from extras.filters import TagFilter
from netbox.filtersets import ChangeLoggedModelFilterSet, OrganizationalModelFilterSet, NetBoxModelFilterSet
from netbox.filtersets import NetBoxModelFilterSet, OrganizationalModelFilterSet
from utilities.filters import ContentTypeFilter, TreeNodeMultipleChoiceFilter
from .models import *


__all__ = (
'ContactAssignmentFilterSet',
'ContactFilterSet',
Expand Down Expand Up @@ -81,7 +80,7 @@ def search(self, queryset, name, value):
)


class ContactAssignmentFilterSet(ChangeLoggedModelFilterSet):
class ContactAssignmentFilterSet(NetBoxModelFilterSet):
q = django_filters.CharFilter(
method='search',
label=_('Search'),
Expand Down
7 changes: 2 additions & 5 deletions netbox/tenancy/forms/model_forms.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
from django import forms
from django.utils.translation import gettext_lazy as _

from extras.forms.mixins import TagsMixin
from extras.models import Tag
from netbox.forms import NetBoxModelForm
from tenancy.models import *
from utilities.forms.mixins import BootstrapMixin
from utilities.forms.fields import CommentField, DynamicModelChoiceField, DynamicModelMultipleChoiceField, SlugField
from utilities.forms.fields import CommentField, DynamicModelChoiceField, SlugField

__all__ = (
'ContactAssignmentForm',
Expand Down Expand Up @@ -122,7 +119,7 @@ class Meta:
}


class ContactAssignmentForm(BootstrapMixin, TagsMixin, forms.ModelForm):
class ContactAssignmentForm(NetBoxModelForm):
group = DynamicModelChoiceField(
label=_('Group'),
queryset=ContactGroup.objects.all(),
Expand Down
4 changes: 2 additions & 2 deletions netbox/tenancy/graphql/types.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import graphene

from extras.graphql.mixins import TagsMixin
from extras.graphql.mixins import CustomFieldsMixin, TagsMixin
from tenancy import filtersets, models
from netbox.graphql.types import BaseObjectType, OrganizationalObjectType, NetBoxObjectType

Expand Down Expand Up @@ -69,7 +69,7 @@ class Meta:
filterset_class = filtersets.ContactGroupFilterSet


class ContactAssignmentType(TagsMixin, BaseObjectType):
class ContactAssignmentType(CustomFieldsMixin, TagsMixin, BaseObjectType):

class Meta:
model = models.ContactAssignment
Expand Down
19 changes: 19 additions & 0 deletions netbox/tenancy/migrations/0012_contactassignment_custom_fields.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Generated by Django 4.2.6 on 2023-11-06 20:23

from django.db import migrations, models
import utilities.json


class Migration(migrations.Migration):

dependencies = [
('tenancy', '0011_contactassignment_tags'),
]

operations = [
migrations.AddField(
model_name='contactassignment',
name='custom_field_data',
field=models.JSONField(blank=True, default=dict, encoder=utilities.json.CustomFieldJSONEncoder),
),
]
4 changes: 2 additions & 2 deletions netbox/tenancy/models/contacts.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from django.utils.translation import gettext_lazy as _

from netbox.models import ChangeLoggedModel, NestedGroupModel, OrganizationalModel, PrimaryModel
from netbox.models.features import TagsMixin
from netbox.models.features import CustomFieldsMixin, TagsMixin
from tenancy.choices import *

__all__ = (
Expand Down Expand Up @@ -109,7 +109,7 @@ def get_absolute_url(self):
return reverse('tenancy:contact', args=[self.pk])


class ContactAssignment(ChangeLoggedModel, TagsMixin):
class ContactAssignment(CustomFieldsMixin, TagsMixin, ChangeLoggedModel):
content_type = models.ForeignKey(
to=ContentType,
on_delete=models.CASCADE
Expand Down

0 comments on commit 2562c87

Please sign in to comment.