fixed netbox.js issue, with display field; fixed api select bootstrap
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
from rest_framework import serializers
|
||||
|
||||
from netbox.api.serializers import PrimaryModelSerializer
|
||||
from netbox.api.serializers import PrimaryModelSerializer, OrganizationalModelSerializer
|
||||
# from netbox_slm.api.nested_serializers import (
|
||||
# NestedRecordSerializer,
|
||||
# NestedNameServerSerializer,
|
||||
@@ -9,18 +9,16 @@ from netbox_slm.models import SoftwareProduct
|
||||
|
||||
|
||||
class SoftwareProductSerializer(PrimaryModelSerializer):
|
||||
display = serializers.SerializerMethodField()
|
||||
url = serializers.HyperlinkedIdentityField(
|
||||
view_name="plugins-api:netbox_slm-api:softwareproduct-detail"
|
||||
)
|
||||
|
||||
class Meta:
|
||||
model = SoftwareProduct
|
||||
fields = (
|
||||
"id",
|
||||
"url",
|
||||
"name",
|
||||
"tags",
|
||||
"custom_field_data",
|
||||
"created",
|
||||
"last_updated",
|
||||
)
|
||||
fields = [
|
||||
'id', 'display', 'url', 'name', 'tags', 'custom_field_data', 'created', 'last_updated',
|
||||
]
|
||||
|
||||
def get_display(self, obj):
|
||||
return obj.name
|
||||
|
||||
@@ -21,6 +21,7 @@ class CustomDynamicModelMultipleChoiceField(DynamicModelMultipleChoiceField):
|
||||
# Modify the QuerySet of the field before we return it. Limit choices to any data already bound: Options
|
||||
# will be populated on-demand via the APISelect widget.
|
||||
data = bound_field.value()
|
||||
|
||||
if data:
|
||||
field_name = getattr(self, "to_field_name") or "pk"
|
||||
filter = self.filter(field_name=field_name)
|
||||
|
||||
+10
-8
@@ -1,4 +1,5 @@
|
||||
from django import forms
|
||||
from django.urls import reverse_lazy
|
||||
from extras.forms import (
|
||||
CustomFieldModelForm,
|
||||
CustomFieldModelCSVForm,
|
||||
@@ -9,13 +10,10 @@ from extras.forms import (
|
||||
from dcim.models import Manufacturer
|
||||
from netbox_slm.models import SoftwareProduct, SoftwareProductVersion
|
||||
from utilities.forms import (
|
||||
BootstrapMixin, DynamicModelChoiceField,
|
||||
BootstrapMixin, DynamicModelChoiceField, APISelect, DynamicModelMultipleChoiceField
|
||||
)
|
||||
|
||||
|
||||
from netbox_slm.fields import CustomDynamicModelMultipleChoiceField
|
||||
|
||||
|
||||
class SoftwareProductForm(BootstrapMixin, CustomFieldModelForm):
|
||||
"""Form for creating a new SoftwareProduct object."""
|
||||
|
||||
@@ -71,12 +69,12 @@ class SoftwareProductBulkEditForm(BootstrapMixin, AddRemoveTagsForm, CustomField
|
||||
class SoftwareProductVersionForm(BootstrapMixin, CustomFieldModelForm):
|
||||
"""Form for creating a new SoftwareProductVersion object."""
|
||||
|
||||
software_product = CustomDynamicModelMultipleChoiceField(
|
||||
software_product = DynamicModelChoiceField(
|
||||
queryset=SoftwareProduct.objects.all(),
|
||||
required=False,
|
||||
# initial_params={
|
||||
# 'device_types': 'device_type'
|
||||
# }
|
||||
widget=APISelect(
|
||||
attrs={"data-url": reverse_lazy("plugins-api:netbox_slm-api:softwareproduct-list")}
|
||||
),
|
||||
)
|
||||
|
||||
# tags = DynamicModelMultipleChoiceField(
|
||||
@@ -88,6 +86,10 @@ class SoftwareProductVersionForm(BootstrapMixin, CustomFieldModelForm):
|
||||
model = SoftwareProductVersion
|
||||
fields = ("name", "software_product",) # "tags")
|
||||
|
||||
# def clean(self):
|
||||
# import pdb;pdb.set_trace()
|
||||
# return super(SoftwareProductVersionForm, self).clean()
|
||||
|
||||
|
||||
class SoftwareProductVersionFilterForm(BootstrapMixin, CustomFieldModelFilterForm):
|
||||
"""Form for filtering SoftwareProductVersion instances."""
|
||||
|
||||
Reference in New Issue
Block a user