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